Re: Bash Menu Script
You should use an If statement and nest the cd command inside like so
This allows you to only execute commands if the statement (the bit between [ and ] ) evaluate to true, in this case we ask bash if the statement [ is $dir a directory ] evaluates to true, if it is bash runs everything from "then" to "fi"
if [ -d "/$dir" ]; then
To add alternative options there is also the "elif" option where you can specify a second possible statement, and the "else" option which is a failsafe incase none of the statements evaluate to true, for example
If deliberately not used proper code here to keep it easy to read for beginners
if [ $dir is in users home dir ]; then
elif [ $dir is a directory outside of users home ]; then
echo $dir isn't your folder
echo $dir isn't a directory
Last edited by CaptainMark; December 7th, 2012 at 11:17 AM.
Catch me on Freenode - imark