On Fri, Feb 18, 2011 at 04:36:06PM +0100, Steffen Daode Nurpmeso wrote: > I am not a sophisticated shell programmer, but i really think this > time it's a shell fault.
You think *what* is the shell's fault? > You may invoke the code snippet via 'script test1 test3' or so. > > #!/bin/sh > set -e > > _t() { > echo "Entry _t for $CURR" > test "$PARAMS" != "${PARAMS/$CURR/}" && { return; } > # Uncomment the next line and the script won't fail! > #echo "Exit _t for $CURR" > } > > PARAMS="$@" > > CURR='test1' _t > CURR='test2' _t > CURR='test3' _t Setting aside for the moment what you are attmepting to do here (which looks rather unorthodox), I don't see what your complaint is. You asked for "set -e", meaning for the shell to exit any time a simple command fails. Then you called three simple commands in a row, each one named "_t". If any of them fails, the shell is supposed to exit. And it does so, yes? Is that what you are complaining about? Are you confused about what your function is doing? It is returning success or failure based on what's in the variables PARAMS and CURR. When it fails, the exit status tells bash to abort, because you asked bash to do so. http://mywiki.wooledge.org/BashFAQ/035 - How can I handle command-line arguments (options) to my script easily? http://mywiki.wooledge.org/BashFAQ/105 -- Why doesn't set -e (set -o errexit) do what I expected?