Re: Variable resolution in shell scripts

From: Green, Simon (SGreen@KRAFTEUROPE.COM)
Date: Thu Jul 11 2002 - 16:00:59 EDT


I'd do it like this...

var[0]="Not Used"
var[1]="first var"
var[2]="second var"
var[3]="third var"
read user_input
echo "User selected the ${var[$user_input]}iation"

I'm sure there's a good O'Reilly book.
But don't forget "AIX Version 4.3 System User's Guide: Operating System and
Devices". Part of the standard manuals on the CD. Chapter 11 covers
shells.

Simon Green
Philip Morris ITSC Europe

AIX-L Archive at http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2
AIX FAQ at http://www.faqs.org/faqs/aix-faq/

N.B. Unsolicited email from vendors will seldom be appreciated.

> -----Original Message-----
> From: Robert Bardos [mailto:Robert.Bardos@ZUGERKB.CH]
> Sent: 11 July 2002 16:01
> To: aix-l@Princeton.EDU
> Subject: Variable resolution in shell scripts
>
>
>
> An easy one for most of you,
>
> given a piece of code like this:
>
> var_1="first var"
> var_2="second var"
> var_3="third var"
> read user_input
> # user enters "2"
> echo "User selected the ????iation"
> # expected result is: "User selected the second variation"
>
> Is there some kind of recursive variable resolution, ie. like
> $var_$user_input, that would resolve into the expected result
> and if yes,
> how would I have to code this?
>
> What book would you recommend for a beginner who wants to
> write some "more
> than trivial" shell scripts? (Or should I leave it at that
> and learn Pearl
> instead?)



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:03 EDT