Passing a var thru a file

Robert Felps felps at convex.com
Wed Jun 19 11:33:10 AEST 1991


In <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

I would assume you'll get plenty answers like,

   var=`cat file`
   eval echo $var

but you might as well speed up the script too,

   var=`< file`
   eval echo $var

 or better yet,

   read var < file
   eval echo $var

unfortunately, these only work in the Korn shell and the last one also
works in later versions of the shell (>SVR2).

Hope this helps,
Robert Felps            I do not speak for  felps at convex.com
Convex Computer Corp    Convex and I seldom Product Specialist
3000 Waterview Parkway  speak for myself.   Tech. Assistant Ctr
Richardson, Tx.  75080  VMS? What's that?   1(800) 952-0379



More information about the Comp.unix.shell mailing list