Re: Getting the return value of the last command run

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Have a read up on using return codes in Bash.

http://tldp.org/LDP/abs/html/exit-status.html

Quick example:

#!/bin/bash

ls foobar 

   if [ $? -eq 0 ] ; then
      echo "successful" 
   else
      echo "not successful"
   fi 

You get the idea..

Cheers,
Chris


On 30 May 2011 15:38, Dotan Cohen <dotancohen@xxxxxxxxx> wrote:
All commands return a value, usually 0 if run properly. For instance, try:
$ ls && echo "done"
$ lsd && echo "done"

The echo command is only executed if the ls command exited
successfully. If one did not add the echo command with the && after a
command, how can he determine if the command exited successfully? I
have a particularly troubling script that gives does not mention if it
exits successfully or not. I could modify it (and probably will some
day) but in general I'd like to know the answer to this question as a
learning experience.

Thanks.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos



--
Kind Regards,
Christopher J. Buckley

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux