bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set -e, but test return not honoured _conditionally_


From: Greg Wooledge
Subject: Re: set -e, but test return not honoured _conditionally_
Date: Tue, 22 Feb 2011 08:46:09 -0500
User-agent: Mutt/1.4.2.3i

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?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]