The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reappearing menu list using select forever_49ers Shell Programming and Scripting 9 09-13-2006 05:05 PM
Dynamic Menu Help ScottKe Shell Programming and Scripting 3 08-30-2006 07:06 PM
Drop down menu in bash for timezone select simonb Shell Programming and Scripting 1 04-29-2006 02:02 PM
dynamic Select menu rawatds Shell Programming and Scripting 2 12-06-2004 05:54 AM
Multiple for loops within a Menu? darthur UNIX for Dummies Questions & Answers 3 12-10-2001 06:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-22-2004
domivv domivv is offline
Registered User
  
 

Join Date: Nov 2003
Posts: 9
Dynamic select with multiple word menu items

Hello all,

I'm developing a deployment script at work and at one point it would need to display something like this:

Which version of ADMIN would you like to deploy?
1) 1.0.0 (store1, 10 Jan 2004)
2) 1.0.1 (store1, 20 Jun 2004)
3) 1.0.2 (store1, 15 Jul 2004)
Select a version :

I know how I could do this in the hardcoded way, BUT the list of menu items being displayed is collected dynamically when needed.

The actual question being : Is it possible to somehow parameterise the select statement so that it displays menu items in which blanks can appear.

Example of hardcoded way :
select option in "one one" "two two"; do
break
done

displays:
1) one one
2) two two

So, how can this "one one" "two two" part in the select be replaced by something that is parameterised.

Thanks.
  #2 (permalink)  
Old 07-22-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
You don't say which shell you are using. Using ksh...
Code:
#!/usr/bin/ksh

set "one one" "two two"

select x in "$@"
do
  break
done

1) one one
2) two two
#?
  #3 (permalink)  
Old 07-22-2004
domivv domivv is offline
Registered User
  
 

Join Date: Nov 2003
Posts: 9
I'm indeed using ksh. I'll give it a try...
Thx
  #4 (permalink)  
Old 07-22-2004
domivv domivv is offline
Registered User
  
 

Join Date: Nov 2003
Posts: 9
Ok, tried it. The example works of course.

Now image that the actual data is completely unknown and dynamically created. The result in my case is put in file. This would mean a flat text file with something like this :

one one
two two

in it.

The contents of the file can be modified to make it work, but I don't seem to succeed.
  #5 (permalink)  
Old 07-22-2004
domivv domivv is offline
Registered User
  
 

Join Date: Nov 2003
Posts: 9
Ok, just figured it out ! For those who might be interested, this is what I did.

1) source file with following contents:
one one
two two

2) the coding:
ix=0
while read record; do
item[$ix]="$record"
ix=$(($ix+1))
done < cat source

set "${item[@]}"

select n in "$@"; do
break
done

3) the result:
1) one one
2) two two
#?
  #6 (permalink)  
Old 07-22-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Example using a file named "source" instead of parameters...
Code:
#!/usr/bin/ksh

IFS="
"
select x in $(<source)
do
  break
done

Note that you may have to restore the original value of IFS afterwards.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0