1

Sorry if it's a dumb q, but I couldn't find the answer! if I have var 1:

STR="hello"

var 2:

letter="T"

I want:

echo ${S${letter}R}

to get "hello", but instead I get bad substitution, what am I doing wrong? Thank you

O. San
  • 1,107
  • 3
  • 11
  • 25

1 Answers1

1
STR="hello"
letter="T"
x="S${letter}R"   # concat string in new variable
echo "${!x}"

Output:

hello

See: What is indirect expansion? What does ${!var*} mean?

Cyrus
  • 84,225
  • 14
  • 89
  • 153