Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!pacbell.com!pacbell!rtech!wrs!roger From: roger@wrs.com (Roger Rohrbach) Newsgroups: comp.unix.shell Subject: Re: Problems with variable substitution in C-Shells Message-ID: <1338@wrs.wrs.com> Date: 11 Dec 90 09:35:31 GMT References: <11585.27563778@ecs.umass.edu> Sender: newsmgr@wrs.COM Lines: 34 Nntp-Posting-Host: time lim@ecs.umass.edu writes: >Suppose I have: >@ num = 5 >set str = num >alias ech 'echo $\!*' >So: >(ech str) will output num, but (ech $str) won't output 5. >In other words: >$str = num, but how may I do something like $($str) ? Another job for "eval"! The following: alias ech 'eval echo \$\!*' will do what you want. The idea here is to build the command: echo $num that will echo the desired value, and then to execute it. (This is known as dynamic programming; Lisp programmers are big fans of this kind of thing). So, we escape the first "$", and the shell will substitute "$str" for "\!*", giving: eval echo \$num and eval will strip off the protective "\", yielding the desire result. -- Roger Rohrbach sun!wrs!roger roger@wrs.com - Eddie sez: ----------------------------------------------- (c) 1986, 1990 -. | {o >o | | \ -) "Two men need one money, but one money needs no man." |