It is currently Tue, 17 May 2022 02:41:28 GMT



 
Author Message
 Help on Double Variables ...
Hi all

I'm trying to define a variable containing another variable.
Something like this, which doesn't work ...
----------------------------------
#! /bin/ksh -f

var=$1

list="toto tata"
for i in $list
do
     name_$i=$var_$i
done

echo $name_toto
echo $name_tata
----------------------------------

Would you know a way to do this ?

Thanx a lot.
--
M. OL -- Olivier Dannhauer                 Antefilms|Productions
o...@unforgettable.com                         http://www.**-**.com/
"Plus ?a rate, plus on a de chances que ?a marche" (Les Shadoks)



 Fri, 19 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

You have to use "eval".

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Fri, 19 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

Sorry, I don't get it ...
In what way could I use "eval" in my ksh loop ?

Thanx
--
OL

----------------------------------
#! /bin/ksh -f

var=$1

list="toto tata"
for i in $list
do
     name_$i=$var_$i
done

echo $name_toto
echo $name_tata
----------------------------------



 Sat, 20 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

for i in $list
do
   eval name_$i=$var_$i
done

--
 Matthew Landt <la...@austin.ibm.com>    _    _  .  _ __.____.     ._
  AIX and HACMP Certified Specialist    | |  / \ |\| |  \. ,_|    _| --
  / Comments, views, and opinions \     | |_/ ^ \|   | ) | |      \, *_)
  \ are mine alone, not IBM's.    /     |___|/~\_\_|\|__/|_|        \(



 Sat, 20 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

It is not entirely clear what you want --- do you want, for
example, name_toto to be assigned the value of the $var_toto
variable, or the value of the $var_ variable followed by "toto",
or something else?  I suppose $var_toto makes most sense, even
though it would be uninitialized in this code fragment.  That'd
become:
   eval name_$i=\$var_$i

                --Ken Pizzini



 Sat, 20 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

Thanx a lot :-)))

--
OL



 Sat, 20 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

Thanx a lot :-)))

--
OL



 Sat, 20 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

In fact, I'm trying to do this :

-------------------------------------------
# far before ...
points_toto="0"
points_tata="0"

list="toto tata"

# then several times in several ways
for i in $list
do
    case $i in
        toto)   points_toto=`expr $points_toto + 1` ;;
        tata)   points_tata=`expr $points_tata + 1` ;;
        ... etc ...
    esac
done
----------------------------------------------
my points_* lists are quite long, that's why :-)))

Any idea ?
Thanx again
--
M. OL -- Olivier Dannhauer                 Antefilms|Productions
o...@unforgettable.com                         http://m.ol.free.fr
"Plus ?a rate, plus on a de chances que ?a marche" (Les Shadoks)



 Sat, 20 Jul 2002 03:00:00 GMT   
 Help on Double Variables ...

#...
for i in $list; do
  eval points_$i="\$((points_$i + 1))"
done

                --Ken Pizzini



 Sat, 20 Jul 2002 03:00:00 GMT   
 
   [ 9 post ] 

Similar Threads

1. Double Variables in a Shell Script - Help Please

2. HELP! Double variable expansion question

3. Double Variable Substitution

4. variable and double quotes

5. double quote variable expansion

6. executing a value of a variable with double-quotes

7. \ creates a double space in variables (csh)

8. Double dereferencing Bourne shell variables

9. sh loop variable and "double indirection"

10. float vs double vs double float


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software