Please see the following script.
basic="a b c"
advance="d e f"
A="basic advance"
for g in $A
do
echo $g
done
The result would be obviously
basic
advance
I want to ask how can i get the following result using $A in for loop
a
b
c
d
e
f
Please see the following script.
basic="a b c"
advance="d e f"
A="basic advance"
for g in $A
do
echo $g
done
The result would be obviously
basic
advance
I want to ask how can i get the following result using $A in for loop
a
b
c
d
e
f
basic="a b c"
advance="d e f"
A="${basic} ${advance}"
for g in $A; do
echo $g
done
Give a try
for value in 'a b c d e f'
do
echo $value
done
Thanks for reply!
The problem is that
The following statement has already been defined in a file and i cannot change it.
A="basic advance"
To change it into your style, i would do
A=`echo $A | sed -e s/' '/'} \${'/g`
A="\${${A}"
but when i run
echo $A
i get:
${basic} ${advance}
which is not the desired result
basic="a b c"
advance="d e f"
A="basic advance"
for g in $A
do
eval echo \$$g
done
root@isau02:/data/tmp/testfeld> cat weekend.ksh
basic="a b c"
advance="d e f"
A="basic advance"
for ele in ${A}; do
eval echo $`echo $ele`
done |\
tr -s " " "\n"
exit 0
root@isau02:/data/tmp/testfeld> ./weekend.ksh
a
b
c
d
e
f