Variable Name Substitution Problem

Variable Name Substitution Problem

Post by j » Sat, 27 Mar 1999 04:00:00



Hello,

I am trying the to achieve the following:

va_env=L
EXPORT=/export_${va_env}
ftf_${va_env}_sc=${EXPORT}/ftf/nomac/import

However if you have ever tried this, it does not work.

It seems as though Shell (ksh) tries to execute the ftf_${va_env}_sc part
rather than substitute the ${va_env} for 'L'.

Is there any way round this (apart from hard coding the L in)

Thanks

John

 
 
 

Variable Name Substitution Problem

Post by Chris Thomps » Sat, 27 Mar 1999 04:00:00




>I am trying the to achieve the following:

>va_env=L
>EXPORT=/export_${va_env}
>ftf_${va_env}_sc=${EXPORT}/ftf/nomac/import

>However if you have ever tried this, it does not work.

The word before the = needs to be literal: no substitutions or quoting.

Quote:>It seems as though Shell (ksh) tries to execute the ftf_${va_env}_sc part
>rather than substitute the ${va_env} for 'L'.

>Is there any way round this (apart from hard coding the L in)

Use

 eval "ftf_${va_env}_sc=${EXPORT}/ftf/nomac/import"

Chris Thompson
Email: cet1 [at] cam.ac.uk

 
 
 

1. Variable substitution within a variable name

Anyone know of a way to use embedded variable names?

i am trying to setup a shell menu for a user to be able to choose a
printer based on their location.  Since their are different numbers of
printers at each location, i am trying to make it dynamic, not static.
I have tried many combinations to no avail so far.

The test script below gets a dynamic list of printers for a particular
store, then should present a menu of those printers for the user to
select. in this case, there are 4 printers so the menu displayed
should be, for example:

1 for printer store032a
2 for printer store032b
3 for printer store032c
4 for printer store032d

Not quite what I am getting.

i=1
lpstat -a | grep store032 | awk '{ print $1 }' |
while read prn
do
   out{$i}=`echo ${prn}`
   echo "$i for printer ${out${i}}"
   i=`expr $i + 1`
done  

Result of running the above script:
printer_names.sh: out1=store032a: not found
printer_names.sh: bad substitution

Anyone have a way to do this, preferably in the bourne shell?

Thanks
--
Robert A. Johnson
Systems Administrator
Cost-U-Less Inc.
8160 304th Ave. SE
Bld. 3 Suite A
Preston, WA 98050
425-222-5022 #161
425-417-2591 (cell)

2. remounting /usr

3. Variable substitution in array name

4. Anyone get the XKEYBOARD extension properly configured?

5. Variable name substitution

6. Does an 8088 (XT w/ 512 RAM) nix exist???

7. C-shell script variable substitution problem/question

8. 2 eth-devices

9. variable substitution problem

10. Problems with variable substitution in C-Shells

11. sh script & variable quoting/substitution problem

12. Big PROBLEM with variable substitution - Gurus go for it !