[ale] exit code and if

Fletch fletch at phydeaux.org
Thu Jul 18 10:34:18 EDT 2002


>>>>> "Andy" == Andy Zyman <Zyman> writes:

    Andy> Hello ALE, as always simple question and looking for Your
    Andy> suggestions:

    Andy> cmd if [ $? -ne 0 ]; then <do smth> fi

    Andy> Is there a better way to this? I mean how i can get rid from
    Andy> this 2 lines and make one ?

        Presuming a Bourne-y shell and `<do smth>' is a simple command
you could always do:

cmd || something else


        But if you need to do several things you could just use the
command itself as the expression for the if (since all it's looking
for is the return value of the command; `[' is just a link to the
`test' command (or a shell builtin of the same name), and all it does
is exit with the apropriate value for the conditional its passed).


if cmd ; then foo ; bar ; baz ; fi
  

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
770 933-0600 x211(w)  |  scary questions." -- Jules                =(___)=
770 294-0820 (m)      |                                               U

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list