Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uwm.edu!linac!att!cbfsb!cbnewsb.cb.att.com!pfinkel From: pfinkel@cbnewsb.cb.att.com (paul.d.finkel) Newsgroups: comp.unix.shell Subject: Re: Use of "eval" in creating new variable names Keywords: eval, shell,help Message-ID: <1991May14.154854.24855@cbfsb.att.com> Date: 14 May 91 15:48:54 GMT References: <1991May13.180547.21281@cbfsb.att.com> <12291@mentor.cc.purdue.edu> Sender: news@cbfsb.att.com Distribution: na Organization: AT&T Bell Laboratories Lines: 38 In article <12291@mentor.cc.purdue.edu> asg@sage.cc.purdue.edu (The Grand Master) writes: >In article <1991May13.180547.21281@cbfsb.att.com> pfinkel@cbnewsb.cb.att.com (paul.d.finkel) writes: >}I have tried things like: eval tty_numb"$count"=`echo $2` >}If I then try to echo the contents of my new variable, all I get is the number: >}Example: echo $tty_numb"$count" This will give me 1 >}expect it. Example: echo $tty_numb1 This will give me tty17 >}echo $tty_numb"$numb" #This where the user chooses a number associated with > > Try: >eval echo $tty_numb$count >--------- It took me a while, but here it is: eval tty_numb"$count"=`echo $2` # This line will create a variable named "tty_numb1". # Its contents will be (for example) "tty12" # Later on I will prompt user for the number corresponding to the user echo "Enter number: \c" read number #Then I can rereference (if such a word exists) my variable like this: eval echo $"tty_numb$number" # ^^^^^^^ will be evaluated first leaving # echo $tty_numb1 # # Then ^ will be evaluated # and eventually my correct tty number will be echoed. # I also created a variable for the user's name called: # nuname"$count". It is rereferenced in the same fashion. #Thank you for your help!