Passing a var thru a file
228-4197,ATTT
rbr at bonnie.ATT.COM
Wed Jun 19 03:34:51 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
>--
>Pat Hertel Canadian Meteorological Centre
>Analyst/Programmer 2121 N. Service Rd.
>phertel at cmc.aes.doe.ca Dorval,Quebec
>Environment Canada CANADA H9P1J3
The shell never sees $ENVAR as a variable, only a string of arbitrary
characters.
Try:
var=`cat file`
echo `eval $var`
Bob Rager
More information about the Comp.unix.shell
mailing list