cron job verification

Bob Bell bbell at macroped.com
Wed Feb 2 10:46:01 EST 2005


On Wed, Jan 12, 2005 at 12:15:46AM -0500, Derek Martin wrote:
>   #!/bin/sh
>   # NEVER start shell scripts as #!/bin/bash -- it can lead to strange
>   # and unintended results.

Like what?  I've never had a problem.  If I specifically am using bash
features, I always say "/bin/bash", as "/bin/sh" could mean Bourne shell
or POSIX shell.

>   rsync <options>
>   if ! $? ; then
>     echo -e "\nrsync completed successfully!\n"
>   else
>     echo -e "\nrsync failed!\n!"
>   fi

That won't work.  As you said, $? will evaluate to an integer, which the
shell will then (unsuccessfully) try to execute.  You want either:

    if rsync <option> ; then

or

    if [ $? -eq 0 ] ; then

or it's ilk.

    - Bob



More information about the gnhlug-discuss mailing list