![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| generating line numbers | sam4now | Shell Programming and Scripting | 7 | 04-28-2008 03:17 PM |
| reappearing menu list using select | forever_49ers | Shell Programming and Scripting | 9 | 09-13-2006 01:05 PM |
| Creating menu list from configuration file | nir_s | Shell Programming and Scripting | 8 | 01-11-2006 12:45 AM |
| generating timer | Confuse | High Level Programming | 5 | 09-16-2003 11:37 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Generating a list of choices in a menu
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 associating the number with the hostname that is confusing me. Here is my code: #!/bin/bash clear COUNT=0 SYSTEMS=`cat systems.txt` while [ "$CHOICE" != "q" ] do for SYSTEM in $SYSTEMS do COUNT=`expr $COUNT + 1` echo "$COUNT. $SYSTEM" done echo "" echo "Please choose." echo "" read CHOICE COUNT=0 clear done What I have so far example: 1. host1 2. host2 3. host3 Please choose. 3 What I'd like example: 1. host1 2. host2 3. host3 Please choose. 3 You picked host3! The hostnames are not always host* of course, so I can't use that as a convention for the script to know which server I mean. Any help would be awesome. Thanks guys. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
assuming your '/tmp/hosts.txt' contains:
Code:
host1 host2 host3 host4 Code:
#!/bin/ksh
hosts='/tmp/hosts.txt'
PS3="Pick one of the above: "
select i in $(< ${hosts})
do
[ $i ] && print "you picked->[${i}]" || print -u2 'invalid selection'
done
|
|
#3
|
|||
|
|||
|
Quote:
|
|
#4
|
||||
|
||||
|
that is cool, I tried this and noticed, i couldnt exit, so did some research on man ksh and then came up with this
select i in $(< hosts.txt) do if [ "$REPLY" = "q" ] then break fi [ $i ] && print "you picked->[${i}]" || print -u2 'invalid selection' done so the content that is typed is stored in REPLY.
__________________
War doesnt determine who is right, it determines who is left |
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
|
Here is what I have now, which is working well. I'm using ssh as a test of the menu. Once I log into the server I choose, and then logout, it doesn't redraw the menu choices again for the next choice. Is there a way I can make it redraw the choices after that first loop completes?
#!/bin/ksh clear HOSTS='systems.txt' PS3="Please choose a system: " select i in $(< ${HOSTS}) do if [ "$REPLY" = "q" ] then break fi [ $i ] && print "" || print -u2 'Invalid Choice' clear ssh -X ${i} done |
|
#7
|
||||
|
||||
|
Code:
#!/bin/ksh
hosts='/tmp/hosts.txt'
PS3="Pick one of the above: "
select i in $(< ${hosts})
do
[ $i ] && print "you picked->[${i}]" || print -u2 'invalid selection'
clear
ssh -X ${i}
nl -s') ' "${hosts}"
done
|
||||
| Google The UNIX and Linux Forums |