LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 05-28-2005, 12:39 AM   #1
tsphan
Member
 
Registered: Jan 2005
Location: Clackamas, Oregon, US
Distribution: Slackware 10.2
Posts: 154

Rep: Reputation: 30
Unhappy bad bashscripting


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?

1) ONE0
2) Music
3) Downloads
4) SharedDocs
#? 2
Mounted ONE0
root @ obelisk :: /mnt/zero1 >>


ONE0 is mounted successfully, but the others aren't. Any help would be greatly appreciated.
 
Old 05-28-2005, 03:45 AM   #2
mjsurette
Member
 
Registered: May 2005
Distribution: spiral, fedora
Posts: 65

Rep: Reputation: 18
Try putting spaces around "=" in your comparisons. You'll find it works much better.

Just out of curiosity, why not use "case"?

Mike
 
Old 05-28-2005, 06:26 AM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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.
 
Old 05-28-2005, 09:05 AM   #4
mjsurette
Member
 
Registered: May 2005
Distribution: spiral, fedora
Posts: 65

Rep: Reputation: 18
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.

Mike
 
Old 05-30-2005, 06:36 PM   #5
tsphan
Member
 
Registered: Jan 2005
Location: Clackamas, Oregon, US
Distribution: Slackware 10.2
Posts: 154

Original Poster
Rep: Reputation: 30
i added the spaces and it worked, thanks everyone who replied
 
Old 05-31-2005, 02:27 AM   #6
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
if in the future you wish to debug your scripts then add -x to #!/bin/bash


#!/bin/bash -x
 
Old 05-31-2005, 04:27 PM   #7
Dave Lerner
Member
 
Registered: May 2005
Location: Florida, USA
Distribution: Pop_OS, Xubuntu
Posts: 152

Rep: Reputation: 44
What does the -x do? I don't see that in "man bash".
 
Old 05-31-2005, 06:16 PM   #8
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
it will run the entire script in debug mode

http://www.tldp.org/LDP/Bash-Beginne...ect_02_03.html

Last edited by heema; 05-31-2005 at 06:18 PM.
 
Old 05-31-2005, 06:53 PM   #9
Dave Lerner
Member
 
Registered: May 2005
Location: Florida, USA
Distribution: Pop_OS, Xubuntu
Posts: 152

Rep: Reputation: 44
Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mount: wrong fs type, bad option, bad superblock on /dev/hdc3 Lordandmaker Linux - Hardware 15 06-05-2011 08:55 AM
mount: wrong fs type, bad option, bad superblock on /dev/cdrom, Adil_uk Linux - Hardware 9 02-16-2005 05:50 PM
mount: wrong fs type, bad option, bad superblock...(cdrom,dvd and floppy) SpItoS Mandriva 14 11-12-2004 02:27 PM
mount: wrong fs type, bad option, bad superblock on /dev/sdb1 pmoreira Linux - Hardware 5 02-26-2004 10:31 AM
wrong fs type, bad option, bad superblock on /dev/hdb1, ldare Linux - Hardware 1 02-12-2004 09:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration