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
Unix Variable Reference and Substitution mugsymark Shell Programming and Scripting 8 06-16-2008 06:24 AM
Reference: WebObjects 5.4.1 Reference iBot UNIX and Linux RSS News 0 03-11-2008 09:50 PM
How to reference a variable within sed? rockysfr Shell Programming and Scripting 1 06-27-2007 05:04 AM
Circular reference fidodido Shell Programming and Scripting 1 09-04-2006 12:04 PM
ms sql command reference inquirer Windows & DOS: Issues & Discussions 2 08-21-2002 11:51 AM

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 10-01-2007
cchaloux cchaloux is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 9
Question Reference Variable

Hi!

I need to determin the most efficient way to do something (rather simple, I thought).

I'm currently echo(ing) a series of menu options, and reading the command input as the number associated with the entry. What I need to do is when the option 1 is selected, that it references a list and then fills in the variable the correct way.

Example - if I have a friendly list of server names like:

1. Server 1
2. Server 2
(...and so on)

However, in the command that I am envoking in the background it needs to be ipaddress : port. I don't want the IP address as the name on the menu, but it does need to be passed for the process to work correctly.

How would I do this?

Thanks!
  #2 (permalink)  
Old 10-01-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
I would have a function that uses a case statement, it takes the option argument and returns the various associated elements with that option in a strict order....

get_menu()
{
case "$1" in
1 )
echo "option one"
echo "flim"
echo "flam"
;;
2 )
echo "option two"
echo "foo"
echo "bar"
* )
return 1;
esac
}

then you could do

get_menu 1 | while read N ....

then you have also centralised all the behaviour of the menu
  #3 (permalink)  
Old 10-01-2007
cchaloux cchaloux is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 9
Hmm...not sure I know what to do with that Any more details? I can't say I've ever done anything like that before...
  #4 (permalink)  
Old 10-01-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
Is this easier?


Code:
PS3="choose:"
select server in  server1 server2;do
	case $server in
		server1)printf "You choose $REPLY : use your ip_1:port here\n";;
		server2)printf "You choose $REPLY : use your ip_2:port here\n";;
		*)printf "Invalid option\n";break;;
	esac
done

  #5 (permalink)  
Old 10-01-2007
cchaloux cchaloux is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 9
Yes, it does! That makes more sense as it's apparent I'm no scripting expert.

Thank you both for your replies!
  #6 (permalink)  
Old 10-02-2007
cchaloux cchaloux is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 9
Exclamation Confusion...

Ok guys, I think I'm missing something here.

I was using radoulov's example and had gotten much further.

I see two things happening that I need to change.

(1) When I select an option from the list, it simply outputs the $REPLY value back to the console. The user doesnt need to see this value, but instead it needs to be passed as a variable to the command to be executed.

(2) Once I select an option from the list, it just keeps prompting me for another option to select and doesn't move on to complete the script. Am I missing an end, or done, or something?
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 06:52 PM.


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