得到previous question的答案,我想看看我是否可以优化下面简化的代码。是否有某种方法将myCorrectVar="${myPrefix}_${mySearch^^}[@]"
的功能合并到for i in
行?
#!/bin/sh
myVar_ANIMAL=("fish" "dog" "emu")
myPrefix="myVar"
mySuffix="animal"
mySearch="${mySuffix}"
myCorrectVar="${myPrefix}_${mySearch^^}[@]"
for i in "${!myCorrectVar}"
do
echo "animal = $i"
done
按预期输出
animal = fish
animal = dog
animal = emu