Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!ncar!gatech!bloom-beacon!mit-eddie!andante!ulysses!dptg!mtune!jrw From: jrw@mtune.att.com (Jim Webb) Newsgroups: comp.unix.shell Subject: Re: variable list of variables Keywords: eval Message-ID: <1991Mar8.221536.2849@mtune.att.com> Date: 8 Mar 91 22:15:36 GMT References: Distribution: comp Organization: AT&T BL Middletown/Lincroft NJ USA Lines: 57 In article robi@bacchus.esa.oz.au (RoBeRt KaRp) writes: >All below is in Bourne shell. >I am trying to acheive the following: > >users="robi henry matt" >for person in $users >do > ${person}_files="something that gives me a list of files say x.c y.c z.c" >done > >What I want to do now is get to the list of files. Something like: > >for file in ${${person}_files} >do > something_to_do_with_file >done > >However, I can't access this, ${${person}_files}, variable. The >shell tells me bad substitution for the above and I can't think >of a way to get ${robi_files} (say) out of this. What you need to do is fiddle with the sh builtin "eval" to do this. One quickly hacked way is the following: users="robi henry matt" for person in $users do # you need both sets of quotes (' & ") otherwise eval will # think you are setting person_files to one thing, and then # a command composed of the rest of the files, eg it will # think you mean robi_files=x.c y.c z.c instead of # robifiles="x.c y.c z.c" eval ${person}_files='"${person}x.c ${person}y.c ${person}z.c"' done for person in $users do echo "${person}_files: \c" for i in `eval echo \\$\${person}_files` do echo "$i \c" done echo done Now, I am sure I've added one too many steps in this mess (at least) but it's getting into the weekend, so, you can fiddle with it :-) Later, -- comp.windows.open-look -&- alt.sex.pictures.d Jim Webb alt.sex.bondage -&- comp.graphics.visualization jrw@mtune.att.com Sex and voyeurism and fantasy... Those who can't do, watch and imagine. --ccs