bash script help?

Colin Watson cjwatson at ubuntu.com
Mon Nov 14 10:09:55 UTC 2011


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

-- 
Colin Watson                                       [cjwatson at ubuntu.com]




More information about the ubuntu-users mailing list