Path: utzoo!attcan!uunet!husc6!cmcl2!nrl-cmf!ames!zodiac!joyce!sri-unix!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.unix.questions Subject: Re: Csh question Message-ID: <181@quintus.UUCP> Date: 20 Jul 88 22:50:12 GMT References: <8807191241.AA18881@decwrl.dec.com> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 29 In article <8807191241.AA18881@decwrl.dec.com> ellis@ultra.dec.com (David Ellis) writes: >Is there any way to get the value of a variable whose name is the value of >another variable? >e.g. if we've done set x=a and set a=3, is there any simple csh expression >in terms of x that yields the value of a (3)? One method is to use "eval". E.g. % set x=a a=3 % eval echo '$'$x prints 3 Another method is to exploit the fact that the "set" command with no arguments prints out the shell variables in alphabetic order, one per line, in the form "". So you can do % set | sed -n -e "s/^$x//p" where is to be replaced by an actual tab character. Rather than using ... `eval echo '$'$x` ... it may be more efficient to use eval set y='$'$x ... $y ... as that doesn't involve forking another shell for the `` form. The Bourne shell also has 'eval' $ x=a a=3 $ eval y='$'$x $ eval echo '$'$x sets y to 3 and prints 3.