Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Hi, I've been trying to make this simple text menu bash script to mount the computer Zero1's shares. When I run this program and I choose ONE0, it works fine. When I run this program and choose any other choice, it still mounts ONE0.
Here is the script, file is called "mount":
#!/bin/bash
echo "What would you like to mount?"
echo
OPTIONS="ONE0 Music Downloads SharedDocs"
select MOUNT in $OPTIONS; do
if [ "$MOUNT"="ONE0" ]; then
mount -t smbfs -o guest //zero1/ONE0\ \(D\) /mnt/zero1/ONE0
echo Mounted ONE0
exit
elif [ "$MOUNT"="Music" ]; then
mount -t smbfs -o guest //zero1/My\ Music /mnt/zero1/Music
echo Mounted Music
exit
elif [ $MOUNT="Downloads" ]; then
mount -t smbfs -o guest //zero1/Downloads /mnt/zero1/Downloads
echo Mounted Downloads
exit
elif [ $MOUNT="SharedDocs" ]; then
mount -t smbfs -o guest //zero1/SharedDocs /mnt/zero1/SharedDocs
echo Mounted SharedDocs
exit
else
echo Not valid share
exit
fi
done
Here are some outcomes:
root @ obelisk :: /mnt/zero1 >> ./mount
What would you like to mount?
1) ONE0
2) Music
3) Downloads
4) SharedDocs
#? 1
Mounted ONE0
root @ obelisk :: /mnt/zero1 >> ./mount
What would you like to mount?
And why do you have exit's after every single mount? That most likely is your problem, you have an exit right after the first mount so the rest of your script is never being executed.
You're right that they're redundant, but not that they're part of the problem. The if .. elif .. elif .. else logic ensures that only one mount will be executed. I would expect this to be the OP's aim, otherwise you'd only need four mount commands.
The problem is that because there are no spaces around the "=" bash interpret's the comparison as an assignment and returns TRUE in the first comparison no matter what the input is.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.