Hello Folks
I am writing this simple program but I am stuck at this point. Here is the snippet from my script where I have issues.
3) echo "Current Directory: $(pwd) Menu 3"
echo -e "Enter a file name\n"
read fname
if [ -f $name ]
then
if [ -x $name ]
then
cat $name
else
echo "You do not have access to file $name"
fi
else
echo "File $name doesn't exist"
echo -e "Press Enter to return to the Main Menu\c"
read dummy
fi
;;
4) clear
echo "Current Directory: $(pwd) Menu 4"
echo -e "Enter a directory name\n"
read dname
if [ -d $dname ]
then
cd $dname
if [ $? -eq 0 ]
then
continue
else
echo "Directory $dname not accessible"
fi
else
echo "Subdirectory $dname does not exist."
echo -e "Press Enter to return to the Main Menu\c"
read dummy
fi
This is a section of the script where it takes entry either 3 or 4. If 3 is selected it prompts for the user to enter filename and if the user is hitting just enter and not any filename, it should return to main menu. But that's not happening, its just looping around and waiting for an input. But if 4 is selected and an enter is pressed with out directory name it goes to that cd $dname part and moves to main menu. Since $dname is empty as the user has not provided any value it goes to home directory of the user.
My requirement is that the script should go back to main menu if the user hits just "enter" with out any value. How can I achieve that?