bash script help?

Nils Kassube kassube at gmx.net
Mon Nov 14 17:04:32 UTC 2011


Knute Johnson wrote:
> On 11/14/2011 2:09 AM, Colin Watson wrote:
> > On Sun, Nov 13, 2011 at 09:40:47PM -0800, Knute Johnson wrote:
> >> I've got a bash script that I run in cron.daily to backup some
> >> data to a jump drive.  One of the commands in my script is to
> >> umount the drive. If I write;
> >> 
> >> if umount /dev/sdb1; then
> >> 
> >>      #do something
> >> 
> >> fi
> >> 
> >> it always does it even if the umount is successful.
> > 
> > The code above means "do something *only* if umount exits
> > successfully".
> > 
> > If you want to do something if umount fails, then you need:
> >    if ! umount /dev/sdb1; then
> >    
> >        # do something
> >    
> >    fi
> 
> Isn't something other than 0 true?

No. The return code 0 means success or true. But there could be several 
reasons for failure, therefore everything else than 0 is failure and the 
number can give a detailed reason for the failure.


Nils




More information about the ubuntu-users mailing list