art vanderlay
art vanderlay

Reputation: 2463

more elegant way to do array using indirect reference in bash

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

Upvotes: 0

Views: 23

Answers (0)

Related Questions