0

FRUIT could be "APPLE" or "BANANA"

And fruit's colors are defined as follows:

APPLE_COLOR=red
BANANA_COLOR=yellow

In a shell, I want to print "red" or "yellow" based on the value of FRUIT. How can I do that?

echo ${"${FRUIT}_COLOR"}

This gives me -bash: ${"${FRUIT}_COLOR"}: bad substitution

John
  • 1,139
  • 3
  • 16
  • 33
  • 1
    What you're looking for is called "indirect expansion". See [BashFAQ #6](https://mywiki.wooledge.org/BashFAQ/006). That said, I'm a little unclear on why a failure would be anything other than expected; do you have a pointer to documentation that implies that the original approach _should_ work? – Charles Duffy Apr 13 '23 at 15:47
  • @CharlesDuffy Oh thanks, I should find another way – John Apr 13 '23 at 23:27

0 Answers0