Chet Ramey wrote: > It depends on what you mean by `fail'. > ... > To do otherwise would have made expr much less useful. Idioms such as
Also I must mention grep too. The exit status of grep isn't just whether it exits without an error but instead returns an indication of whether the pattern matched or not. This makes idioms such as this possible: if grep -q PATTERN FILE; then ... do something ... fi But if used by itself as a filter the exit status may be non-zero and that isn't an error condition. I have seen a lot of people run into 'set -e' and grep collisions. grep PATTERN FILE1 > FILE2 Which is why I like to use sed for this instead. Then the exit code reflects errors and not pattern matches and can be more easily used to handle errors such as a full disk. sed -n '/PATTERN/p' FILE1 > FILE2 || exit 1 Bob