You are not logged in.
Hi! i made this little and useful (for me) script to mount my isos in my mount points, but im having problems validating the entered values, the while instruction is the one i dont know how to enter the "or" option...
TNKS!! hope you can find it useful!
#!/bin/bash
echo Select the mount point:
echo 1. /mnt/iso
echo 2. /mnt/iso2
echo 3. /mnt/iso3
echo 4. /mnt/iso4
read point
#while ( $point != "1" || $point != "2" || $point != "3" || $point != "4" ); do
# echo invalid option
# echo Select a valid mount point
# read point
#done
case $point in
1) sudo mount -o loop -t iso9660 "$1" /mnt/iso1 && echo "$1" mounted to /mnt/iso1;;
2) sudo mount -o loop -t iso9660 "$1" /mnt/iso2 && echo "$1" mounted to /mnt/iso2;;
3) sudo mount -o loop -t iso9660 "$1" /mnt/iso3 && echo "$1" mounted to /mnt/iso3;;
4) sudo mount -o loop -t iso9660 "$1" /mnt/iso4 && echo "$1" mounted to /mnt/iso4;;
*)
esac
echo Select dir to umount:
echo 1. /mnt/iso1
echo 2. /mnt/iso2
echo 3. /mnt/iso3
echo 4. /mnt/iso4
read upoint
#while ( $upoint != "1" || $upoint != "2" || $upoint != "3" || $upoint != "4" ); do
# echo invalid option
# echo Select a valid mount point
# read upoint
#done
case $upoint in
1) sudo umount /mnt/iso1 && echo /mnt/iso1 umounted;;
2) sudo umount /mnt/iso2 && echo /mnt/iso2 umounted;;
3) sudo umount /mnt/iso3 && echo /mnt/iso3 umounted;;
4) sudo umount /mnt/iso4 && echo /mnt/iso4 umounted;;
*)
esac
exit 0
Last edited by leo2501 (2008-01-26 16:15:52)
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline
I think remove sodo from script and run script with:
sudo script.sh
And if you want "or" try to use "if".
Offline
Try this:
while [[ $point != "1" || $point != "2" || $point != "3" || $point != "4" ]]; do
echo invalid option
echo Select a valid mount point
read point
done
Kind of a guess! Have you come across the advanced bash scripting guide? http://tldp.org/LDP/abs/html/
From chapter 7.1:
Using the [[ ... ]] test construct, rather than [ ... ] can prevent many logic errors in scripts. For example, the &&, ||, <, and > operators work within a [[ ]] test, despite giving an error within a [ ] construct.
Offline
nop, it doesnt work, even if i enter 1,2,3,4 always says "invalid option"
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline
Maybe you meant something like this (with AND!):
while [ "$point" != "1" ] && [ "$point" != "2" ] && [ "$point" != "3" ] && [ "$point" != "4" ]; do
larch: http://larch.berlios.de
Offline
Perfect! here is the finished script
#!/bin/bash
echo Select the mount point:
echo 1. /mnt/iso1
echo 2. /mnt/iso2
echo 3. /mnt/iso3
echo 4. /mnt/iso4
echo 5. /mnt/cdrom
read point
while [ "$point" != "1" ] && [ "$point" != "2" ] && [ "$point" != "3" ] && [ "$point" != "4" ] && [ "$point" != "5" ]; do
echo invalid option
echo Select a valid mount point
read point
done
case $point in
1) sudo mount -o loop -t iso9660 "$1" /mnt/iso1 && echo $1 mounted to /mnt/iso1 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso1 && echo /mnt/iso1 umounted;;
2) sudo mount -o loop -t iso9660 "$1" /mnt/iso2 && echo $1 mounted to /mnt/iso2 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso2 && echo /mnt/iso2 umounted;;
3) sudo mount -o loop -t iso9660 "$1" /mnt/iso3 && echo $1 mounted to /mnt/iso3 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso3 && echo /mnt/iso3 umounted;;
4) sudo mount -o loop -t iso9660 "$1" /mnt/iso4 && echo $1 mounted to /mnt/iso4 && echo --- Press a key to umount --- && read && sudo umount /mnt/iso4 && echo /mnt/iso4 umounted;;
5) sudo mount -o loop -t iso9660 "$1" /mnt/cdrom && echo $1 mounted to /mnt/cdrom && echo --- Press a key to umount --- && read && sudo umount /mnt/cdrom && echo /mnt/cdrom umounted;;
*)
esac
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline
Hey, just my 2 cents,
http://devmanual.gentoo.org/tools-refer … ts-in-bash
Apparently double brackets are better than single. I've just started trying to get into bash scripting, and I ran into that, pretty interesting.
Very nice script btw, definitely adding it to my growing collection
Offline