Link to home
Start Free TrialLog in
Avatar of Los Angeles1
Los Angeles1

asked on

Linux scripting question, return code of last command

How do I determine the return code of the last command

I want to know if it was successful or not
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just run the below command

echo $?

if result is 0 (zero) then last command was successful

You could do

if [ $? -eq 0 ]; then
   echo "Command succeeded!"
    # Some more action to celebrate this success ...
   else
      echo "Command failed"
      # More action to bemoan this failure ...
fi