[KLUG Members] getting exit code in bash script

Bruce Smith bruce at armintl.com
Fri Mar 11 13:07:03 EST 2005


That's because you need to execute something in the "if" statement.
If you uncomment the echo statements, it works fine.

If you really want to do nothing, give it a no-op statement, which is
just a colon.

Please follow up to this thread on the programming list.

 - BS


> I tried this:
> 
> #!/bin/sh
> ls
> exitcode=$?
> if [ $exitcode -eq 0 ]
>    then
>       #echo "Everything is O.K."
>    else 
>       #echo "$exitcode"
> fi
> 
> and still get errors:
> 
> ./testexitcode.sh: line 9: syntax error near unexpected token `fi'
> ./testexitcode.sh: line 9: `fi'




More information about the Members mailing list