打印数组中项目的值

时间:2015-02-20 11:26:48

标签: bash shell variables

我有一个变量设置为:

X="AA BB CC DD EE"
Y="AA DD EE"

然后每个值都有自己的值,如下所示:

AA="after"
BB="before"
CC="care"
DD="driver"
EE="escape"

然后我需要遍历这些变量并需要打印相应的值。

for myloop in `echo $Y`
do
    # Now I need to print each variable  
    echo ${$myloop} # if its value is number then I can use ((myloop)) to print it
done

输出应为:

after
driver
escape

如何使用shell脚本实现此目的?我没有使用任何阵列。

0 个答案:

没有答案