Umavmishra
asked on
exit 0 in shell script is exiting from session
Hi All,
I have a menu driven script which exits on a switch case statement as below
Please let me know what is the problem with the exit statement given in the code snippet. When I select option 5 on the menu, I get logged off the linux session
I have a menu driven script which exits on a switch case statement as below
Please let me know what is the problem with the exit statement given in the code snippet. When I select option 5 on the menu, I get logged off the linux session
while :
do
clear
echo " MAIN M E N U"
echo " 1. Get files"
echo " 2. Run Application"
echo " 3. Delete files "
echo " 4. Do ALL of the above"
echo " 5. Exit"
echo " "
echo " "
echo -n "Please enter option [1 - 5]"
read opt
case ${opt} in
1) echo "Getting files ";
get_files
;;
2) echo "Executing Application";
executeapp
;;
3) echo "Deleting files older than 2 weeks in directory";
delete_files;
;;
4) echo "Doing everything!";
get_files;
executeapp;
delete_files;
;;
5) exit 0;
;;
*) echo "$opt is an invaild option. Please select option between 1-5 only";
echo "Press [enter] key to continue. . .";
read enterKey
;;
esac
done
how do you invoke the script, and what do you want to happen when you select option 5 on the menu?
If you get logged off when you select option 5, it means it is most likely invoked from your .profile
with something like
exec /path/to/menu.sh
The exec will overlay the current process (in this case the login) with menu.sh, so that when you exit the menu, you are immediately logged off.
You need to change your .profile to just call the menu without the exec, eg:
/path/to/menu.sh
with something like
exec /path/to/menu.sh
The exec will overlay the current process (in this case the login) with menu.sh, so that when you exit the menu, you are immediately logged off.
You need to change your .profile to just call the menu without the exec, eg:
/path/to/menu.sh
ASKER
my .profile does not have any reference to this script.
how do you invoke the script?
ASKER
. ./script.sh
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
typo
*look=loop
*look=loop