Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#
# Script to mount and list everything on a USB drive. The drive is unmounted at the end
#
echo "Mounting USB drive"
mount /mnt/usb
# Did the previous command throw up anything?
if [$? -gt 0] then
# There was a problem check it out
if [$? -eq 32] then
# Drive is already mounted, just display it's contents and unmount
ls /mnt/usb -al
umount /mnt/usb
echo "Unmounting USB drive"
else
# Some other problem, assume nothing connected
echo "There are currently no compatible USB drives connected"
fi
exit 1
else
# Drive mounted without problem, display it's contents and unmount it
ls /mnt/usb -al
umount /mnt/usb
echo "Unmounting USB drive"
fi
exit 0
but when I run it I get the following error:
line 17: syntax error near unexpected token 'else'
As far as I can see everything is OK, does any know what the problem is?
Thanks meblost, 100% correct. Those changes sorted it out perfectly. Just one more question, do you know of any way to suppress the OS output. When a drive isn't connected I get the bash line
mount: /dev/sdb1 is not a valid block device
before my line about no compatible drives connected. Ideally I would just like my output to be displayed.
There's another error in the script: the first $? is the return code from the mount command. The if statement will execute a test command and the second $? is the return code from that command, probably not what you intended. To test the same rc in both ifs, assign it to a variable immediatley after mount:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.