04-29-2006
Fixed!
OK, I wrote a script that does near-enough what I wanted to do...
PHP Code:
#!/bin/bash
#Read time zones into array
i=1; for item in `cat timezones.txt`; do tz[$i]="$item"; let i=$i+1; done
i=1
echo "Locate timezone using up/down arrow keys then press enter to select."
while [ 0 ]; do
if [ $i -eq 0 ]; then i=1; fi
if [ ! ${tz[$i]} ]; then let i=i-1; fi
echo -en "\r "
echo -en "\r${tz[$i]}"
read -sn 1 twiddle
case "$twiddle" in
"B")
let i=i+1
;;
"A")
let i=i-1
;;
"")
echo
echo "OK to select ${tz[$i]} (y/N)?"
read -sn 1 confirm
if [ "$confirm" == "y" -o "$confirm" == "Y" ]; then
break
else
echo "Locate timezone using up/down arrow keys then press enter to select."
fi
;;
esac
done
echo
echo "Final choice was ${tz[$i]}"
The above script is fine for newer bash however CDLinux contains a really old version of bash that doesn't support the -en switches for the read command nor does it support arrays. After much faffing I managed to re-write the script to be backward compatible.
PHP Code:
#!/bin/bash
#Read time zones into array
function key_mode() {
if [ $1 -a $1 = "on" ]; then
stty_state=`stty -g`
stty raw; stty -echo
else
stty "$stty_state"
fi
}
i=1; for item in `cat timezones.txt`; do eval tz$i="$item"; let i=$i+1; done
i=1
echo "Locate timezone using up/down arrow keys then press enter to select."
key_mode on
while [ 0 ]; do
eval selection=\$tz$i
if [ $i -eq 0 ]; then
i=1
eval selection=\$tz$i
fi
if [ ${#selection} -lt 2 ]; then
let i=i-1
eval selection=\$tz$i
fi
echo -en "\r "
echo -en "\r$selection"
twiddle=`dd bs=1 count=1 2>/dev/null`
#read -sn 1 twiddle
case "$twiddle" in
`echo -e "\102"`)
let i=i+1
;;
`echo -e "\101"`)
let i=i-1
;;
`echo -e "\015"`)
key_mode off
echo
echo "OK to select $selection (y/N)?"
key_mode on
confirm=`dd bs=1 count=1 2>/dev/null`
if [ "$confirm" = "y" -o "$confirm" = "Y" ]; then
break
else
key_mode off
echo "Locate timezone using up/down arrow keys then press enter to select."
key_mode on
fi
;;
esac
done
key_mode off
echo
echo "Final choice was $selection"
Last edited by simonb; 05-01-2006 at 11:25 AM..
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all
is menu driven by SELECT can be a dynamic ?
My requirement is that i want SELECT to be created on run time not predefine . The select should be created as per the no of
words in a file
thanks in advance
rawat (2 Replies)
Discussion started by: rawatds
2 Replies
2. Shell Programming and Scripting
How to create a drop down menu in either bash or ksh? (3 Replies)
Discussion started by: proactiveaditya
3 Replies
3. Shell Programming and Scripting
Hi All,
I am trying to use the select command & the menu.
below mention is my script
#!/bin/bash
2
3 PS3="Is today your birthday? " #PS3 system variable
4
5 echo "\n"
6
7
8 select menu_selection in YES NO QUIT
9 do
10
11 ... (1 Reply)
Discussion started by: milindb
1 Replies
4. Web Development
I need to create a dynamic drop down menu which is populated by entries such as;
htdocs/client1/index.php
htdocs/client2/index.php
htdocs/client3/index.php
htdocs/client4/index.php
etc.
So htdocs/client*/index.php
Is this possible?
I know how to do this using normal arrays, but not... (2 Replies)
Discussion started by: JayC89
2 Replies
5. Shell Programming and Scripting
Hi All,
I need to develop a bash script list “list of files” and able to select if any and set as globe variable in script and use for other function.
I would like to see in menu format.
Example out put
Below are the listed files for database clone
1. Sys.txt
2. abc.txt
3. Ddd.txt... (1 Reply)
Discussion started by: ashanabey
1 Replies
6. Shell Programming and Scripting
Hi Team,
I have a requirement to login into URL using username and password , then I have to select a "particular name" from drop-down menu and then Read the values user records etc.... using perl.
Is it possible to do in perl script ? (OR) Can you please let me know which scripting... (1 Reply)
Discussion started by: latika
1 Replies
7. Shell Programming and Scripting
A lot of my scripting makes use of the 'select' command to create menu driven input. A typical example of how I use it is as:
somevar=''
PS3='Select one: '
while ]; do
select somevar in $(sqlplus -s $dbuser/$dbpw@mydb <<EOF
set echo off feedback off verify off... (7 Replies)
Discussion started by: edstevens
7 Replies
8. What is on Your Mind?
Have just added (after missing for some time), the latest version of Google Site Search for our site in the Navbar Search Menu:
https://www.unix.com/members/1-albums215-picture791.png
Cheers and Enjoy.
Here is the URL for that link in case you need it:
https://goo.gl/P8p82c (4 Replies)
Discussion started by: Neo
4 Replies
9. Shell Programming and Scripting
hi i am new to bash scripting ..
i created a bunch of folders but only want the folder names with file1. so i go in and make an array to grab the folders the put in a file then i strip the directories so i just have the folder names i need then i would like to make the menu with a selection... (3 Replies)
Discussion started by: lamby22
3 Replies