4 Matching Annotations
- Nov 2022
-
stackoverflow.com stackoverflow.com
-
That's an important remark. find /path/to/ -iname '*.gif' -o -iname '*.jpg' -print0 will only print the jpg files! You need brackets here: find /path/to/ \( -iname '*.gif' -o -iname '*.jpg' \) -print0
-
- Nov 2020
-
wresch.github.io wresch.github.io
-
Important caveat: in the combined expression, if the middle command has a non-zero exit status, then both the middle and the rightmost command end up getting executed.
I don't think that is surprising, is it? Since && and || have the same order of precedence. So I think this is more of a clarification than a caveat.
I think this is just because:
a && b || c is equivalent to: (a && b) || c (so of course c gets evaluated if
(a && b)
is false (that if eithera
orb
is false).I think they just mean, in this case:
bedmap && mv || fail
if
mv
fails, thenfail
still gets executed.Easier to see with a simpler example:
⟫ true && false || echo 'fail' fail ⟫ false && true || echo 'fail' fail
Better example/explanation here: https://hyp.is/-foxmCVXEeuhnLM-le_R4w/mywiki.wooledge.org/BashPitfalls
The caveat/mistake here is if you treat it / think that it is equivalent to if a then b else c. That is not the case if b has any chance of failing.
-
-
-
The potential problem: if second_task fails, third_task will not run, and execution will continue to the next line of code - next_task, in this example. This may be exactly the behavior you want. Alternatively, you may be intending that if second_task fails, the script should immediately exit with its error code. In this case, the best choice is to use a block - i.e., curly braces: first_task && { second_task third_task } next_task Because we are using the -e option, if second_task fails, the script immediately exits.
-
-
stackoverflow.com stackoverflow.com
-
[[ -z "$a" || -z "$b" ]] && usage
-