c shell script; Howto use environement variables to build environment variables and take their value

c shell script; Howto use environement variables to build environment variables and take their value

Post by Gert villem » Fri, 01 Feb 2002 22:17:09



In a script I wish to specify two environment variables like this;

setenv FOO bee
setenv ${FOO}_ROOT /home/bee

This is ok and will set "FOO=bee" and "bee_ROOT=/home/bee".

Now I wan't to build the "bee_ROOT" variable using "FOO" and use the
value in a expression, i.e. something like this;

source ${${FOO}_ROOT}/.cshrc

This will not execute. The error is "Variable syntax". It seems that
the shell cannot figure to evaluate the inner ecpression first and
then the outer. I have tried different combination of forcing
evaluation with '' and assigning to variable first etc, but with
little luck.

Any idea/explanation why this is not possible/what I can do instead?

Cheers,
Gert.

 
 
 

c shell script; Howto use environement variables to build environment variables and take their value

Post by Seb » Fri, 01 Feb 2002 22:22:42


eval source \${${FOO}_ROOT}/.cshrc

--Seb



Quote:> In a script I wish to specify two environment variables like this;

> setenv FOO bee
> setenv ${FOO}_ROOT /home/bee

> This is ok and will set "FOO=bee" and "bee_ROOT=/home/bee".

> Now I wan't to build the "bee_ROOT" variable using "FOO" and use the
> value in a expression, i.e. something like this;

> source ${${FOO}_ROOT}/.cshrc

> This will not execute. The error is "Variable syntax". It seems that
> the shell cannot figure to evaluate the inner ecpression first and
> then the outer. I have tried different combination of forcing
> evaluation with '' and assigning to variable first etc, but with
> little luck.

> Any idea/explanation why this is not possible/what I can do instead?

> Cheers,
> Gert.


 
 
 

c shell script; Howto use environement variables to build environment variables and take their value

Post by Tinti » Sat, 02 Feb 2002 06:26:50



Quote:> In a script I wish to specify two environment variables like this;

> setenv FOO bee
> setenv ${FOO}_ROOT /home/bee

> This is ok and will set "FOO=bee" and "bee_ROOT=/home/bee".

> Now I wan't to build the "bee_ROOT" variable using "FOO" and use the
> value in a expression, i.e. something like this;

> source ${${FOO}_ROOT}/.cshrc

> This will not execute. The error is "Variable syntax". It seems that
> the shell cannot figure to evaluate the inner ecpression first and
> then the outer. I have tried different combination of forcing
> evaluation with '' and assigning to variable first etc, but with
> little luck.

> Any idea/explanation why this is not possible/what I can do instead?

http://www.grymoire.com/Unix/CshTop10.txt
 
 
 

1. How to get value of environment variable in variable name?

I have the name of an environment variable in a shell script variable,
and would like to get at the value of that environment variable.  This
happens to be in a ksh script, but I'm looking for a generic solution
that would also work in the standard Bourne shell (i.e, not a ksh
specific solution).  In Perl, this is trivial, but I haven't found the
right incantation of eval or backticks or indirection to get this
working.

For example, if I have an environment variable named BAR whose value is
"foo", and I have a script variable named var whose value is "BAR", how
do I assign "foo" to another variable in the script?

  var=BAR
  value=???

Thanks,
Alfred

2. STUPID C question

3. Difference between shell variables and environment variables!

4. ~username problem

5. difference between shell variable and environment variable

6. xv compilation on Solaris 2.2

7. detecting difference between unset variable and variable whose value is null in Korn Shell

8. I just got mysql installed on my redhat sendmail server...

9. getting environment variables from c shell using Bourne shell

10. How to change the value of an environment variable in a script.

11. file contents into variable, or global variable from shell script

12. How do i transfer the contents of shell variable to a variable used in C program

13. shell environement variables