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.

Required fields*

4
  • Since this is just [ $? -ne 0 ] in disguise, I will stick with a simplified version: last_block_failed() { [ $? -ne 0 ];}. ShellCheck doesn't complain this way. Thanks for the solution (it also improves readability even further). Commented Jan 27, 2023 at 15:17
  • 1
    @Andrew15_5, ShellCheck should complain about the missing quotes in there which make it subject to $IFS-splitting. Or write it last_block_failed() [[ $? -ne 0 ]] or last_block_failed() (( $? != 0 )) Or last_block_failed() (( ! $? )) Commented Jan 27, 2023 at 15:54
  • It doesn't complain because $? stores the exit code of a previous command, which implies that $? is a number and doesn't have spaces or newlines (I don't know who would assign a digit to IFS). Hence, it's safe to use it without quotes. And [ <> -ne 0 ] is a perfectly valid command which is another form of test <> -ne 0 (it returns 0 if the expression is true and 1 if false). Commented Jan 27, 2023 at 19:57
  • 1
    @Andrew15_5, [ $? -ne 0 ] in another language would be written equal(glob(split($?)), 0) which makes no sense. [ "$?" -ne 0 ] would be equal($?, 0) which makes sense. See also Security implications of forgetting to quote a variable in bash/POSIX shells Commented Jan 27, 2023 at 21:51