Problem: Shell Variable inside Variable ????

Problem: Shell Variable inside Variable ????

Post by James M Sherman » Tue, 29 Mar 1994 23:23:48




>I would like to know if there is a way to put a variable inside a variable,
>AND be able to adress them both. This was not very elegantly put but in
>short this is what I'm trying to do:
>      A=B
>      B=C
>      echo ${A}       (should output "B" which it does)
>      echo ${${A}}    (should output "C" since the result of ${A}
>                       is "B", giving ar real call to ${B})


eval echo ${${A}} will work.
--


DEEP THOUGHTS, by Jack Handey                                                                      It's too bad that whole families have to be torn apart                          by something as simple as wild dogs.

 
 
 

Problem: Shell Variable inside Variable ????

Post by Harald Eikr » Wed, 30 Mar 1994 07:53:47


! eval echo ${${A}} will work.
! --
!

!
! DEEP THOUGHTS, by Jack Handey .......

Ah, but how deep?

No, of course it won't work.  Did you actually test it before announcing?
Better try

  eval echo \$$A

or maybe

  eval echo $"$A"

  ~~h

 
 
 

Problem: Shell Variable inside Variable ????

Post by Clark L. Za » Wed, 30 Mar 1994 10:05:33


for GRP in `echo ${DPT}`

where ` is the character at the upper left corner of your
keyboard.  

--


 
 
 

Problem: Shell Variable inside Variable ????

Post by Arif Diwan (B » Thu, 31 Mar 1994 23:23:01




 ! eval echo ${${A}} will work.
 ! --
 !

 !
 ! DEEP THOUGHTS, by Jack Handey .......

 Ah, but how deep?

 No, of course it won't work. Did you actually test it before announcing?
 Better try

 eval echo \$$A

 or maybe

 eval echo $"$A"
<<<

Nope. The last two do not work quite right. The $$ evaluate to the current
process pid.

This works:

foo=bar

A=\$foo

eval echo $A

--


                                                617/873-6274

 
 
 

Problem: Shell Variable inside Variable ????

Post by John H. Kits » Thu, 31 Mar 1994 23:48:17




> >I would like to know if there is a way to put a variable inside a variable,
> >AND be able to adress them both. This was not very elegantly put but in
> >short this is what I'm trying to do:
> >      A=B
> >      B=C
> >      echo ${A}       (should output "B" which it does)
> >      echo ${${A}}    (should output "C" since the result of ${A}
> >                       is "B", giving ar real call to ${B})

> eval echo ${${A}} will work.

almost.  you have to escape the first "$".  it should read

        eval echo \${${A}}

--

                        Murray Hill, NJ

 
 
 

1. Formattet output inside variable / line brak inside variable

Hi everybody,

i am using the tcsh under freebsd

i want query a mysql DB wich have approx 100 entrys and generate
multiple template files.

The problem is that the direct output to a variable doesnt work there
are differences between the output into a text file and a variable.

I don't want to use a text file for data generation.

is there any possibility to preformat the variable input in that form
that i can do an echo $variable and get an output like sample OUTPUT2 ?

Regards Michael

-- Output1: directly at a tcsh
host01:/home/ux/mytest> host01:/home/ux/mytest> echo "select
id,nr,color,length,type,count(length) from patch.cable  group by
length,type,color;" | mysql -ur -pr -B

id      nr      color   length  type    count(length)
032     132     grey    1000    std     6
020     120     grey    2000    std     12
001     100     grey    3000    std     13

Output2: generated in a tcsh and written to a file

host01:/home/ux/mytest>  echo "select
id,nr,color,length,type,count(length) from patch.cable  group by
length,type,color;" | mysql -ur -pr -B > test1.txt

host01:/home/ux/mytest> less test1.txt
id      nr      color   length  type    count(length)
032     132     grey    1000    std     6
020     120     grey    2000    std     12
001     100     grey    3000    std     13

Output3 generated in a tcsh and written to a variable

host01:/home/ux/mytest> set test125=`echo "select
id,nr,color,length,type,count(length) from patch.cable  group by
length,type,color;" | mysql -ur -pr -B`

host01:/home/ux/mytest> echo $test125
id nr color length type count(length) 032 132 grey 1000 std 6 020 120
grey 2000 std 12 001 100 grey 3000 std 13

2. add a raid 5 system to a rh7.2 linux

3. Expanding a shell variable that may contain shell variables.

4. Restoring from a 'ufsdump' backup under an earlier SVR4 release?

5. Evaluate a variable that is inside a string variable

6. telnetting

7. variable inside of variables

8. SCSI HD on AHA2940,IDE-CDROM setup

9. How do i dereference a variable inside a variable?

10. csh shell, problem with echoing variable variables...

11. Setting variables in a variable array of null variables

12. Reading HTTP POST Variables in Shell Variables - HOW?

13. Creating shell variable containing substring of another variable.