Passing a var thru a file

Larry Martell larry at st-andy.uucp
Wed Jun 19 05:32:37 AEST 1991


In article <1991Jun18.153222.20836 at cid.aes.doe.CA> afsipmh at cidsv01.cid.aes.doe.CA () writes:
>Say i have a file that (just for the sake of this question) contains
>just one word:
>$ENVAR
>
>Say $ENVAR is an environmental variable
>
>What is it about the shell that prevents interpretation:
>
>#!/bin/sh
>var=`cat file`
>echo $var     #gives (literally) $ENVAR
>echo `echo $var`  #also gives (literally) $ENVAR

You need to tell the shell to re-evaluate the expression. The shell IS 
expanding $var (it equals $ENVAR), but you want it to expand $var, and
then expand it again.  You do this using eval:

#!/bin/sh
var=`cat file`
eval echo $var

-- 
Larry Martell                  "Opinions are like assholes; everybody has one, 
212-668-9478		        but nobody wants to look at the other guys"
uunet!st-andy!larry



More information about the Comp.unix.shell mailing list