Groups > Unix Linux > Linux > Re: Capturing program return codes in a bash script?




Re: Capturing program return codes in a bash script?

Re: Capturing program return codes in a bash script?
Wed, 2 Apr 2008 21:33:46 +0000
On Wed, 2 Apr 2008 21:30:42 +0000 (UTC), Bit Twister wrote:
> On Wed, 02 Apr 2008 16:19:19 -0500, Ivan Marsh wrote:
>>
>> How do I determine if an command completed successfully when run from
a
>> bash script to decide what the script should do next?
>
> Depends on the application.
> Usually return code is in $?
>
> Example:
> ping -c 1 -w 3 $_target_host > /dev/null
> if [ $? -eq 0 ] ; then

Oops. that should read
  if [ $? -ne 0 ] ; then
    echo "Ping failure on  $_target_host"
    exit 1
  fi

For extra points read
man test
Post Reply
about | contact