Linux scripting question, return code of last command

Posted on 2011-10-28
Medium Priority
Last Modified: 2013-12-10
How do I determine the return code of the last command

I want to know if it was successful or not
Question by:Los Angeles1
  • 2
LVL 68

Accepted Solution

woolmilkporc earned 2000 total points
ID: 37046942
The variable $? Contains the returncode of the last command.

LVL 40

Expert Comment

ID: 37046944
just run the below command

echo $?

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

LVL 68

Expert Comment

ID: 37047074
You could do

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

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question