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.

8
  • 1
    the exit status of an if statement is zero, if none of the then/else branches were taken. if false; then false; fi leaves the exit status to 0, but if true; then false; fi leaves the exit status to 1. (even though in both cases the last command to run was false, and yes, I think it could return some other nonzero status too.)
    – ilkkachu
    Commented Oct 4, 2021 at 14:51
  • @ilkkachu Thanks. I was definitely not attempting to make generic statements about this. I have amended the text to use more careful language.
    – Kusalananda
    Commented Oct 4, 2021 at 14:58
  • Also is_match should probably just be is_match() { grep -qFe "$1" file.txt; } or is_match() { grep -qF -- "$1" file.txt; }, unless you do also want to store the matching line in $m (but then that would be poorly chosen name for that global reply variable) Commented Oct 4, 2021 at 15:08
  • 1
    I have edited the question to make $m a local variable.
    – fuumind
    Commented Oct 4, 2021 at 15:17
  • 1
    @they, yeah. I think I just find the behaviour a bit odd, i.e. why would it not just leave the exit status of the last command in effect, regardless of if it was in a condition or in the inner branches. There's probably a sensible reason, but in a way it warrants a comment in my mind...
    – ilkkachu
    Commented Oct 4, 2021 at 17:24