ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
while :
do
clear
echo " M A I N - M E N U"
echo "1. Contents of /etc/passwd"
echo "2. List of users currently logged"
echo "3. Prsent handling directory"
echo "4. Exit"
echo -n "Please enter option [1 - 4]"
read opt
case $opt in
1) echo "************ Conents of /etc/passwd *************";
more /etc/passwd;;
2) echo "*********** List of users currently logged";
who | more;;
3) echo "You are in $(pwd) directory";
echo "Press [enter] key to continue. . .";
read enterKey;;
4) echo "Bye $USER";
exit 1;;
*) echo "$opt is an invaild option. Please select option between 1-4 only";
echo "Press [enter] key to continue. . .";
read enterKey;;
esac
done
I got with your simple file but how to protect ctrl-c and ctrl z?
I want to also direct logout for current user when program exit.
Now I arrived home directory of user when press program exit and ctrl-c.
#!/usr/bin/env bash
# Disable ^Z
stty susp ^-
# Handle ^C
trap prompt_exit INT
prompt_exit () {
trap "" INT
read -p "Do you wish to exit? [y/N]" USRIN
if [ "$USRIN" == 'y' -o "$USRIN" == 'Y' ]
then
# If we're a login shell logout, otherwise call `exit`
logout
fi
trap prompt_exit INT
}
while :
do
# Menu goes here
done
I got with your simple file but how to protect ctrl-c and ctrl z?
I want to also direct logout for current user when program exit.
Now I arrived home directory of user when press program exit and ctrl-c.
Thanks
Please
You can use the TRAP command in Linux to handle the Ctrl+C and Ctrl+Z commands. A simple google search might even help you get the exact code you are looking for.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.