Le 01/06/2012 23:56, Arno Teunisse a écrit :

One question about compound variables :

# uname -a on my linux give me back :
#Linux arnot-VirtualBox 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7
14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
# So I use the following code to store the items I want into a compound
variable:
str=$(uname -a)
typeset -C uname # declare a compound variable
uname.os=${str:0:5} # ${str:start:length} is substr ( perl speaking )
uname.virtualMachine=${str:6:16}
uname.linuxKernel=${str:23:16}
uname.osName=${str:40:10}
uname.date=${str:55:27}
uname.arch=${str:84:5}
uname.end=${str:104:9}

# trying , in a loop to get at the values :

for i in ${!uname.*}
do
print $i '->' ${i} VALUE??

done

output of the script :
uname.arch -> uname.arch VALUE??
uname.date -> uname.date VALUE??
uname.end -> uname.end VALUE??
uname.linuxKernel -> uname.linuxKernel VALUE??
uname.os -> uname.os VALUE??
uname.osName -> uname.osName VALUE??
uname.virtualMachine -> uname.virtualMachine VALUE??

I do not get back the value of the compound variable : What am I doing
wrong ???

use nameref to evaluate the value of $i :

str="Linux arnot-VirtualBox 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux"
...
for i in ${!uname.*}
do
        nameref j=$i
        print $i '->' $j

done

also, take a look at src/cmd/ksh93/tests and
http://svn.nrubsig.org/svn/people/gisburn/scripts/

Regards,

Cyrille Lefevre
--
mailto:[email protected]


_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to