Referencing an env var from an env var

Referencing an env var from an env var

Post by Paul Grave » Wed, 30 Jul 1997 04:00:00



I am trying to reference an environment variable from within an
environment variable.

    HOME=/home/paul
    x=HOME
    echo $"$x"

    gives me $HOME and not /home/paul
or
    HOME=/home/paul
    x=\$HOME
    echo $x

    gives me $HOME and not /home/paul

I could write a c program that would use getenv recursively, but it
would me more aesthetically pleasing to use a (simple ?) shell command.
Is there anything I'm missing, or am I attempting the impossible ?

I am using ksh on HP-UX 10.20

Please email any thoughts as well as posting them.  Thanks

Paul Graves

EDS Electronic Commerce
Cheadle, Cheshire, UK

 
 
 

Referencing an env var from an env var

Post by Minh H. Ca » Tue, 05 Aug 1997 04:00:00


Try this

     HOME=/home/paul
     x=$HOME
     echo $x

good luck

Minh


> I am trying to reference an environment variable from within an
> environment variable.

>     HOME=/home/paul
>     x=HOME
>     echo $"$x"

>     gives me $HOME and not /home/paul
> or
>     HOME=/home/paul
>     x=\$HOME
>     echo $x

>     gives me $HOME and not /home/paul

> I could write a c program that would use getenv recursively, but it
> would me more aesthetically pleasing to use a (simple ?) shell command.
> Is there anything I'm missing, or am I attempting the impossible ?

> I am using ksh on HP-UX 10.20

> Please email any thoughts as well as posting them.  Thanks

> Paul Graves

> EDS Electronic Commerce
> Cheadle, Cheshire, UK


 
 
 

Referencing an env var from an env var

Post by Ronald Fische » Wed, 06 Aug 1997 04:00:00


>>>>> On Tue, 29 Jul 1997 09:12:55 +0100


PG> I am trying to reference an environment variable from within an
PG> environment variable.
PG>
PG>     HOME=/home/paul
PG>     x=HOME
PG>     echo $"$x"
PG>
PG>     gives me $HOME and not /home/paul
You question and your example seem to contradict each other. If you
have
    HOME=/home/paul
and would like to display
    /home/paul
this would be done by
    echo $HOME
but that's trivial, so I suppose you intended something different -
maybe you can rephrase your question and give an appropriate example.

Also, your question looks suspiciously as if a look at
    man eval
would help...
--

http://ourworld.compuserve.com/homepages/ronald_fischer/
[When posting a followup, mailing a courtesy copy is fine, provided it is
clearly marked as such.]

 
 
 

Referencing an env var from an env var

Post by Brian McCaule » Wed, 06 Aug 1997 04:00:00



> Also, your question looks suspiciously as if a look at
>     man eval
> would help...

Really?  Since "eval" is a shell built-in it usually lacks it's own
separate man page.  I concur that "eval" is what is needed.

--

 .  _\\__[oo       from       | Phones: +44 121 471 3789 (home)

.  l___\\    /~~) /~~[  /   [ | PGP-fp: D7 03 2A 4B D8 3A 05 37...
 # ll  l\\  ~~~~ ~   ~ ~    ~ | http://wcl-l.bham.ac.uk/~bam/

 
 
 

Referencing an env var from an env var

Post by Jan Tellkam » Thu, 07 Aug 1997 04:00:00



> I am trying to reference an environment variable from within an
> environment variable.

>     HOME=/home/paul
>     x=HOME
>     echo $"$x"

>     gives me $HOME and not /home/paul
> or
>     HOME=/home/paul
>     x=\$HOME
>     echo $x

>     gives me $HOME and not /home/paul

> I could write a c program that would use getenv recursively, but it
> would me more aesthetically pleasing to use a (simple ?) shell command.
> Is there anything I'm missing, or am I attempting the impossible ?

> I am using ksh on HP-UX 10.20

Hi Paul,

I'm using bash under HP-UX 10.20.

#!/home/tellkamp/bin/bash
if [ -f /usr/local/bin/e4rc ] ; then
   . /usr/local/bin/e4rc &>/dev/null            # set environment
else
   exit 1
fi

DIR=$(eval echo \${$1})                        # $1 is smthng like HOME
# now DIR is the string given in $1, it can be expanded wih ${DIR}

echo -e "building in ${DIR} on host \n$(banner ${HOST})\n"
cd ${DIR} ; make
exit $?

--
Jan Tellkamp
Flensburg, 06. August 1997

 
 
 

Referencing an env var from an env var

Post by Andreas Schw » Thu, 07 Aug 1997 04:00:00


|> DIR=$(eval echo \${$1})                        # $1 is smthng like HOME

Another Useless Use of Command Substitution.

eval DIR=\${$1}
--
Andreas Schwab                                      "And now for something

 
 
 

Referencing an env var from an env var

Post by Chris Jone » Sat, 09 Aug 1997 04:00:00




> > I am trying to reference an environment variable from within an
> > environment variable.

> >     HOME=/home/paul
> >     x=HOME
> >     echo $"$x"

> >     gives me $HOME and not /home/paul
> > or
> >     HOME=/home/paul
> >     x=\$HOME
> >     echo $x

> >     gives me $HOME and not /home/paul

> > I could write a c program that would use getenv recursively, but it
> > would me more aesthetically pleasing to use a (simple ?) shell command.
> > Is there anything I'm missing, or am I attempting the impossible ?

> > I am using ksh on HP-UX 10.20

> Hi Paul,

> I'm using bash under HP-UX 10.20.

> #!/home/tellkamp/bin/bash
> if [ -f /usr/local/bin/e4rc ] ; then
>    . /usr/local/bin/e4rc &>/dev/null            # set environment
> else
>    exit 1
> fi

> DIR=$(eval echo \${$1})                        # $1 is smthng like HOME
> # now DIR is the string given in $1, it can be expanded wih ${DIR}

> echo -e "building in ${DIR} on host \n$(banner ${HOST})\n"
> cd ${DIR} ; make
> exit $?

> --
> Jan Tellkamp
> Flensburg, 06. August 1997

HOME=/your/account
eval x=$HOME
echo $x will output /your/account


 
 
 

Referencing an env var from an env var

Post by Jan Tellkam » Sat, 09 Aug 1997 04:00:00




>|> DIR=$(eval echo \${$1})                        # $1 is smthng like HOME

> Another Useless Use of Command Substitution.

> eval DIR=\${$1}

Thanks for the way to light ;-)
But it was not useless, because it works.

Jan
Flensburg, 08. August 1997

 
 
 

Referencing an env var from an env var

Post by Sabina Brva » Fri, 22 Aug 1997 04:00:00


Quote:> > I am trying to reference an environment variable from within an
> > environment variable.
> >     HOME=/home/paul
> >     x=HOME
> >     echo $"$x"
> >     gives me $HOME and not /home/paul
> > or
> >     HOME=/home/paul
> >     x=\$HOME
> >     echo $x
> >     gives me $HOME and not /home/paul

Why don't you try simply :

HOME=/home/paul
x=$HOME
echo $x

Why make it simple, eh? ;-)

Sabina

ps: basic understandings of $ in shell - it 'evaluates' variable
                        and =          - simple assignment

 
 
 

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. requested resource is in use

3. setting $DISPLAY env var

4. Top 10 subjects comp.unix.shell

5. IE (Windows only)/Apache-Env Var not being passed???

6. GIS - street mapping software for Linux?

7. that sun env var thing -- it's the old LD_LIBRARY_PATH thing right?

8. AIX pthread Stability

9. man pages - MANPATH env var

10. How to find env var passed to a process?

11. Problem getting Env Vars with Mod_SSL

12. netcg problem - says no DISPLAY env var

13. PATH and env var files...?