adars1
March 19, 2010, 9:12pm
1
I am trying to parse a string using delimited char into array.
BNAME=B10,B20,B30
B10.Q=X
B20.Q=Y
B30.Q=Z
I need to parsethe BNAME into array, then i will loop through array to execute command using these variables. like:
for i in $array
do
qload array [i]array[i].Q # execute command: qload B10 X
done
adars1:
I am trying to parse a string using delimited char into array.
BNAME=B10,B20,B30
B10.Q=X
B20.Q=Y
B30.Q=Z
I need to parsethe BNAME into array, then i will loop through array to execute command using these variables. like:
for i in $array
do
qload array [i]array[i].Q # execute command: qload B10 X
done
IFS=, set -- $BNAME
for b
do
qload "$b" "$b.Q"
done
Hi, adars1:
B10.Q
A dot is not a valid character in a shell variable.
Perhaps something like this will work for you:
#!/bin/sh
BNAME='B10 B20 B30'
B10=X
B20=Y
B30=Z
set -- $BNAME
for name in "$@"; do
eval echo qload \$name \$$name
done
Running it gives:
$ ./adars1.sh
qload B10 X
qload B20 Y
qload B30 Z
When you're ready to try it for real, remove the "echo" following the eval command.
Regards,
Alister
adars1
March 21, 2010, 10:32am
4
BR_NAME='DONEBR10 DONEBR20'
# queue name
DONEBR10=X
DONEBR20=Y
set -- $BR_NAME
for name in "$@";
do
eval echo \$name \$$name
echo "---ddddd--------------------------"
done
-- I got follwing output
DONEBR10 DONEBR20 X DONEBR20