Passing a var thru a file

Passing a var thru a file

Post by afsi.. » Thu, 20 Jun 1991 00:32:22



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.        

Environment Canada         CANADA           H9P1J3

 
 
 

Passing a var thru a file

Post by 228-4197,AT » Thu, 20 Jun 1991 02:34:51



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

>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

 
 
 

Passing a var thru a file

Post by Ray Walla » Thu, 20 Jun 1991 04:23:22



>Say i have a file that (just for the sake of this question) contains
>just one word:
>$ENVAR

It actualy isn't peculuar to files.

Quote:>var=`cat file`
>echo $var     #gives (literally) $ENVAR

Try
        eval echo $var

---
Ray Wallace            

                (UUCP)          ...!decwrl!oldtmr.enet!wallace

---

 
 
 

Passing a var thru a file

Post by Larry Marte » Thu, 20 Jun 1991 04:32:37



>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 *s; everybody has one,
212-668-9478                    but nobody wants to look at the other guys"
uunet!st-andy!larry

 
 
 

Passing a var thru a file

Post by Robert Fel » Thu, 20 Jun 1991 10:33:10



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

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

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

 
 
 

1. Need help not passing make vars as env vars in gmake.

A feature of gmake is that environment variables can be used just like
make variables. The only problem is that it also converts the current make
variables into environment variables for the use of any commands or makes
that you execute.

This would all be fine except for the fact that SCO unix has a very small
maximum environment size. I have done everything I can to not use much
environment space, but often I still get the error:
execve: /bin/sh: Arg list too long

- this is for trying to execute the command 'make -C dtAdmin install'

Does anyone know of a way to turn off the conversion of make variables into
environment variables??

Thanks

Wesley Dunnington


2. Fun with Cron

3. Question: passing $var and "$var" into AWK from script

4. startx gives problems

5. telnet file "pass-thru" to local system??

6. IRQ routing and USB audio on Dell Inspiron 4100

7. Passing file descriptors thru rexec() socket

8. Netscape Messanger crashing

9. Reading and passing vars from a file.

10. Passing value of C var to Script file

11. Passing commands thru a shell script

12. Passing client IP address thru reverse mod_proxy

13. pass thru printing with visionfs