Question : exit status in shell script

I am writing a shell script which uses commands like ssh, scp. Whenever any command fails I want to exit out of the script with an exit status. Please advise how can I do that.

Answer : exit status in shell script

If you want different actions based on each command, do
1:
2:
3:
4:
5:
6:
7:
8:
9:
some-command
 
if [ $? -ne 0 ]
then
   echo "command failed"
   exit 1
else
   echo "command succeeded"
fi
Open in New Window Select All
Random Solutions  
 
programming4us programming4us