Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Always paste your script into https://shellcheck.net, a syntax checker, or install shellcheck locally. Make using shellcheck part of your development process. Commented 2 days ago
  • 2
    @waltinator Thanks for the pointer; shellcheck finds no issue though. Commented 2 days ago
  • 1
    Is this for just a one-off or occasional regex match in your script? If so, using bash regex matches is fine. If not, if you're using it in, say, a while read loop or a for loop, then you really should rewrite that section of the script to use sed or awk or perl. If regex matches are the majority of the script then rewrite the whole thing in either awk or perl, optionally with a shell wrapper. Use shell for what it's good at, and use other tools for what they're good at. Commented yesterday
  • @cas The real expression is used to check for any of a fixed number of keywords with the same meaning ("n", "no", "none", "0", "false" or, which creates the complication, an empty string ) that may be present in a variable, once, in the beginning of the script. I think the use case is totally fine. Commented yesterday