[vox-tech] bash, short circuit logic, and errexit

Bryan Richter bryan.richter at gmail.com
Fri Jan 18 12:53:05 PST 2008


Oh, it does make sense that the expressions of branch statements are
ignored, and by extension, statements with && or ||, since they can be
used the same way. i.e.
" _statement_  && do_things" is the same as "if  _statement_ ; do
do_things; fi". Clearly you wouldn't want the script to die simply
because you skipped some conditional code. :)

The most compact way to get around this is probably "_&&-expression_ || exit".

In my case, that's

diff -q $file1 $file2 && echo "No differences" || exit

Or, after reading diff's manual, I guess I could just do

diff -s $file1 $file2

:)

-B


More information about the vox-tech mailing list