Drop down menu in bash for timezone select


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Drop down menu in bash for timezone select
# 1  
Old 04-29-2006
Drop down menu in bash for timezone select

Is there any way to implement a drop down menu selection in bash?

This is on CDLinux which is a very minimal live CD and I am using it to install an image onto a hard drive. Part of that process is the timezone selection. There are just too many timezones to attempt to use the "select" command. It would just scroll off the screen and be gone.

CDLinux has lynx and I concidered using it and an HTML form but there is no way to post the output to any type of cgi script without a webserver running on the machine.

If not in bash, then are there any handy programs I could compile that would implement a drop down menu selection?
# 2  
Old 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+1done
i
=1
echo "Locate timezone using up/down arrow keys then press enter to select."
while [ ]; do
  if [ 
$i -eq 0 ]; then i=1fi
  
if [ ! ${tz[$i]} ]; then let i=i-1fi
  
echo -en "\r                            "
  
echo -en "\r${tz[$i]}"
  
read -sn 1 twiddle
  
case "$twiddlein
    
"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" -"$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 [ $
-$"on" ]; then
    stty_state
=`stty -g`
    
stty rawstty -echo
  else
    
stty "$stty_state"
  
fi
}
i=1; for item in `cat timezones.txt`; do eval tz$i="$item"let i=$i+1done
i
=1
echo "Locate timezone using up/down arrow keys then press enter to select."
key_mode on
while [ ]; 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 "$twiddlein
    
`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" -"$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..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stuck with menu in select

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

2. What is on Your Mind?

Google Site Search in Search Drop Down Menu (Again)

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

3. Shell Programming and Scripting

Help with 'select' for menu input

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

4. Shell Programming and Scripting

How to select a particular field from a drop-down menu in a webpage using perl script?

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

5. Shell Programming and Scripting

File Select Menu Script

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. Web Development

Dynamic Drop Down Menu

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

7. Shell Programming and Scripting

Error using select menu command

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

8. Shell Programming and Scripting

Drop down menu

How to create a drop down menu in either bash or ksh? (3 Replies)
Discussion started by: proactiveaditya
3 Replies

9. Shell Programming and Scripting

dynamic Select menu

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
Login or Register to Ask a Question