Bash script conditions

Jonathan Duncan jonathan at jkdwebmagic.com
Wed Jul 12 07:45:13 MDT 2006


On Wed, 12 Jul 2006, Stuart Jansen wrote:

> On Wed, 2006-07-12 at 06:22 -0600, Jonathan Duncan wrote:
>> I just do not know the syntax.  I saw a list of "Exit Values" in the rsync
>> man page but how do I check for those?
>
> If you don't care about the exact return code in event of an error, you
> can include the rsync command in the if statement.
>
> if rsync foo bar baz
> then
>  echo success
> else
>  echo failure
> fi
>
> If you care about the return code, immediately after running rsync, add
> RC=$?
> The variable $? contains the return code of the last command to execute.
>
> if [ 0 -eq $RC ]
> then
>  echo "Shells are weird, 0 == success == true"
> fi
>
> Check the builtin bash help for test
> help test
> to find out about the various types of tests.
>
>

Thank you, Stuart and Byron.  Very helpful!

Jonathan


More information about the PLUG mailing list