[Tfug] Problem checking return code in bash script

Nate nate at torzo.com
Wed Oct 7 09:56:46 MST 2009


I just created a test script that is identical to yours except that I
call a different script since I don't have ruby or rails, and it works
perfectly.

#!/bin/sh
sudo su -l -c 'boguscommand' user2
if [ ! $? = 0 ]; then echo "failed" && exit; fi
echo "got here"

$ sh test.sh
-su: boguscommand: not found
failed
$

So no clue on why it doesn't work for you...

Nate

On 10/05/2009 09:23 PM, Chad Woolley wrote:
> I'm writing a script which automates system setup, with logic like this:
> 
> sudo su -l -c "ruby ~/railsci/setup_rails_dependencies.rb" ci
> if [ ! $? = 0 ]; then echo "Unable to setup rails dependencies" && exit; fi
> 
> However, even if the command returns a non-zero return code (tested by
> running manually), the script keeps going and doesn't exit.
> 
> What am I doing wrong?  References/links to docs are welcome.
> 
> Thanks,
> -- Chad
> 
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org




More information about the tfug mailing list