0

taking the answer to a previous question, I would like to see if I can refine my code that is simplified below. Is there someway to merge the function of myCorrectVar="${myPrefix}_${mySearch^^}[@]" into the for i in line?

#!/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

gives output as expected

animal = fish
animal = dog
animal = emu
art vanderlay
  • 2,341
  • 4
  • 35
  • 64
  • Maybe [codereview](http://codereview.stackexchange.com) is better place for this kind of questions. – dmadic May 10 '18 at 16:16
  • `/bin/sh` does not know about arrays. Maybe you meant `/bin/bash`? – Kusalananda May 10 '18 at 16:39
  • If you manage to answer it, add it as your own answer :p. SO encourages to do that. – LMC May 10 '18 at 16:52
  • @ that other guy, this is not asked as a nested question. I did not make reference to ${${}} . I was asking if there was another way such as using quotes, ticks or brackets that I am not aware of. – art vanderlay May 10 '18 at 19:15

0 Answers0