[KLUG Members] getting exit code in bash script

bill bill at billtron.com
Fri Mar 11 13:23:49 EST 2005


On Fri, 2005-03-11 at 13:07, Bruce Smith wrote:
> That's because you need to execute something in the "if" statement.
> If you uncomment the echo statements, it works fine.

Not on this RH box, nor on a SUSE box.  I commented the lines thinking
there was something amiss in the echo statements.  

But this doesn't work:

#!/bin/sh
ls
exitcode=$?
if [ $exitcode -eq 0 ]
   then
      echo "Everything is O.K."
   else 
      echo the exit code for ls was: $exitcode
fi

It lists the files but responds with the error message:

./testerror.sh: line 9: syntax error near unexpected token `fi'
./testerror.sh: line 9: `fi'


b.



More information about the Members mailing list