LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-16-2008, 02:31 AM   #1
please
Member
 
Registered: Apr 2007
Posts: 195

Rep: Reputation: 30
script menu file


Hi all

How to write script file to choice and run command?

I mean Display Menu

1. nslookup
2. ping
3. reboot
4. poweroff

0.exit

I want to logout current user when press 0.

Best Regards
Please
 
Old 12-16-2008, 02:45 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Look here: http://tldp.org/LDP/Bash-Beginners-G...ect_09_06.html
 
Old 12-17-2008, 07:44 AM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Smile hope this helps.

Code:
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
Regards,
VIKAS
 
Old 12-17-2008, 09:36 AM   #4
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
Hi

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
 
Old 12-18-2008, 10:22 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
simpler:

Code:
select choice in john paul ringo george; do echo $choice;break;done
1) john
2) paul
3) ringo
4) george
#? 2
paul
you need to break out of it.
more control? run it through case
 
Old 12-18-2008, 11:07 AM   #6
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
Code:
#!/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
 
Old 12-19-2008, 10:42 PM   #7
please
Member
 
Registered: Apr 2007
Posts: 195

Original Poster
Rep: Reputation: 30
Hi

I got with your configuration
Sorry for my reply delay

 
Old 01-02-2009, 03:27 AM   #8
dhanyaelizabeth
LQ Newbie
 
Registered: Jan 2009
Posts: 27

Rep: Reputation: 15
Quote:
Originally Posted by please View Post
Hi

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.



Linux Archive

Last edited by dhanyaelizabeth; 01-10-2009 at 03:08 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script help... menu to pick file from folder bfellenr Linux - Newbie 13 01-15-2011 03:30 PM
shell script menu marsIV Programming 1 10-09-2007 08:56 PM
Grub Menu doesn't reflect menu.lst file fatsheep Linux - Software 4 06-11-2007 01:29 PM
Create a script to display file name, Inode, and size of any file. Has to be a script JaxsunApex Linux - Newbie 7 01-29-2007 08:15 PM
K Menu - calling html/webpage file from menu sKAApGIF Linux - Desktop 2 08-24-2006 07:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration