I have the follwing - cat ~/ABCFILE | grep "$SYSTEM" | grep "$USERNAME"
What I'm looking to do is have the variable for $SYSTEM determined by the user making a selection from a numbered list. So, input 1 would be system ABC etc.
whoami gives you the username of the person logged on (or sudo'ed into the account). Most shells have the USER environment variable but sudo will usually unset it. whoami works always.
If you have ksh use a select loop. It generates a simple numbered menu out of a list that you must supply. It uses the same syntax as a for loop.
If you omit 'in <list>' it will default to using "$@" (quoted command line arguments)
This command displays the PS3 prompt for a reply. So set that to something meaningful before running the select command.
so if you did:
Your user will see a menu and prompt as follows:
1) ABC
2) DEF
3) GHI
Select the number of your system:
You need the 'break' in there in order to exit the select loop in an orderly fashion. Otherwise select will go on forever unless you issues a <Ctrl>D.
I have implied but not said until now that when your user selects a number the corresponding menu item will be placed in the variable 'system'. The actual number will be placed in the built-in variable 'REPLY', in case you want to make use of that. So if the user selects '2' then "$system" = "DEF" and $REPLY = 2.
Lastly, you can build a dynamic list, more or less. I've used select lists based upon files in a directory that look something like this:
Last edited by rwuerth; 01-15-2009 at 01:08 PM..
Reason: learned to use code blocks
Hi all
Only learning so if any mistakes, let me know
I am trying to create a menu box with Whiptail, taking in the variables from a txt.file called Name.txt which has just 4 names listed for now, one below each other..ie
Dave
John
Mike
Mary
Bash script is below and calls the txt... (8 Replies)
hey all, me again....having a problem with my code, where I essentially am trying to show a menu, have the user select an option (from 1 to 5), then display which selection they picked...
#!/bin/bash
# A LIST OF THE ERROR MESSAGES AND THE PROPER SYNTAX:
error_0="Correct amount of... (1 Reply)
I want something that would show up basically like:
Menu
-----
1) Option 1
2) Option 2
3) Option 3
Pick one:
I tried menu = " Menu \r\n ----- \r\n 1)Option 1 \r\n..............etc etc etc"
but that didnt work (just got the whole menu one one line, with the... (2 Replies)
The code im having problems with is highlighted in red, upon selecting option 2 on the main menu (highlighted green) my echo "NETWORK CONNECTIVITY" command seems to get overlooked and the resulting output is "Thank you for using the Operator Administrative Tool." being displayed. Can anyone tell me... (2 Replies)
Hello, im taking a class of Unix and i dont really know much about it, im trying to create a list of menu a user would select from and im very lost. Basically it will have 5 options, the user will chose from:
1. list files in the pwd
2. display date and time
3. is the file file or directory
4.... (5 Replies)
is there a way I can make the menu list reappear when I use select ?
-----
menulist="Change_title Remove_tag Change_tag Add_line Quit"
select word in $menulist #change_title remove_tag change_tag add_line quit
do
case $word in
# first menu option Change Title
... (9 Replies)
Hi folks,
I have the following function ,which generates menu for installation type:
select_install_type()
{
echo
echo ========================================
echo Please select the type of installation:
echo ========================================
... (8 Replies)
Hello all,
I have the below script and I'm a little stuck on the best way to continue.
Essentially I'm creating a text file (systems.txt) with a list of servers in it by hostname. Then I would like to echo a menu with each hostname and a number to use to pick it from the list. It's somehow... (7 Replies)