using return values in shell scripts

From: Jim Showalter (highpriest_at_earthlink.net)
Date: 09/30/04


Date: Thu, 30 Sep 2004 00:05:31 GMT

How can I conditionally use the return code of a command ('mount' in this
case) in a shell script?

I want to do something like:

#!/bin/sh

# first, mount the SMB volume

val=`mount -t smbfs -o username=jill,password="" //HAL/C /mnt/hal`

if [ $val -eq 0 ] ; then
    echo "$val"
    ls /mnt/hal
    smbumount /mnt/hal
else
    echo "$val"
    echo "Cannot mount //HAL/C on /mnt/hal"
    echo "$val"
    exit 1
fi

exit 0

-- 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/  Everything should be made as simple as possible, but not simpler.
_/                           -- Albert Einstein
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


Relevant Pages

  • Re: [kde-linux] Mounting with exec flag
    ... I have a WD external drive and when I mount it through KDE, ... stuff), how can I tell it to mount this drive with the exec, flag? ... And I can copy a shell script to both devices and then execute ...
    (KDE)
  • RE: smb share
    ... I had a problem also mount a smb share until I upgraded to 2.2.8. ... successfully with the following command smbclient ... unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe ...
    (RedHat)
  • Re: automount usb flash drive?
    ... attach command on the umass* action. ... >> when I do the following command line command the usb flash drive mount fine ... unless you give it 777 permissions. ... > I found that making a one-line shell script to do the mounting is much ...
    (freebsd-questions)
  • Re: [SLE] User mounting smbfs
    ... >> I've been trying to configure fstab, to allow a user to mount an smb ... You should put the smb mount in fstab. ... can you mount it on the command line OK? ...
    (SuSE)
  • Re: Mounting external USB disk
    ... Note that a backup disk should only be mounted when its being accessed - ... The shell script needs to be a bit longer than three lines. ... minimum to check the termination codes output by mount, rsync and umount ...
    (uk.comp.os.linux)