On Mon, 2 Oct 2000, Gideon Guillen wrote:

> In MS-DOS batchfiles, there's this thing called error codes or error levels
> that's generated whenever a program or batchfiles exits/terminates. For
> example, for normal termination, it would be '0' or let's say '1' if a
> certain event was trapped by a batchfile. In MS-DOS, this is the
> environment %ERRORLEVEL%. What is it's equivalent on *NIX/Linux shells,
> preferably in bash.

It's called exit status but I don't think it's an environment variable by
default. The default exit status of 0 is interpreted as successful
completion of the program/process just executed.

There's a sample file in the bash documentation subdirectory under
examples/functions/exitstat that shows how you can check a processes
exitstatus using a bash function. 

The info pages for bash also give clues how to use this.

It might be illustrative to give you an example though.  I hope that the
following commands issued at the bash prompt will give you an idea of how
to use exit status in your script.

bash:~$ if ls ; then echo "all is well." ; else echo "something wrong"; fi

You could set ERRORLEVEL to something by adding a line in your script that
goes:

        if foo ; then ERRORLEVEL=0 ; else ERRORLEVEL=1 ; fi

You can then proceed to do conditionals in your script by evaluating
$ERRORLEVEL. 

I hope this helps.

--
eric pareja ([EMAIL PROTECTED]) <O> Here, have a clue. Get the picture.
PGP key at htp://gra.ph/~xenos/xenos.pusa.pgp <|PLUG|> http://gra.ph
"Knowledge is inherently precious even if you can't sell it."
   - Dr. Greta Penninger in Bruce Sterling's "Distraction"



_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

Reply via email to