[KLUG Members] getting exit code in bash script

Bruce Smith bruce at armintl.com
Fri Mar 11 13:32:51 EST 2005


I copied/pasted your lines into a script on my SuSE 9.2 box and it runs
fine for me.

Maybe you have some unprintable character in your script or something?
Try putting the text from the second echo in double quotes, or send your
script to me privately as an _attachment_.

And I repeat:  PLEASE FOLLOW UP TO THE PROGRAMMING LIST!!!

 - BS


> 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'




More information about the Members mailing list