Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!st-andy!larry From: larry@st-andy.uucp (Larry Martell) Newsgroups: comp.unix.shell Subject: Re: Passing a var thru a file Message-ID: <1991Jun18.193237.20647@st-andy.uucp> Date: 18 Jun 91 19:32:37 GMT References: <1991Jun18.153222.20836@cid.aes.doe.CA> Reply-To: uunet!st-andy!larry (Larry Martell) Distribution: na Organization: RMJ Securities Corp. Lines: 26 In article <1991Jun18.153222.20836@cid.aes.doe.CA> afsipmh@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