1

What is wrong in this substitution.

$ m_d_ver=0.2
$ m=mod
$ d=dom
$ echo ${$m_$d_ver}
-bash: ${$m_$d_ver}: bad substitution

Thanks,

user2230605
  • 2,390
  • 6
  • 27
  • 45
  • "What is wrong in this syntax?" -- err, that it isn't the language's actual syntax? Did you find any document or reference that made you think the original proposal *would* be allowed? – Charles Duffy Oct 20 '15 at 23:39

1 Answers1

7

What you're trying to do is an indirect variable lookup. The syntax for that is ${!namevar}, where namevar is a variable that contains the name you actually want to evaluate. Thus:

mod_dom_ver=0.2
m=mod
d=dom
var=${m}_${d}_ver
echo "${!var}"

See BashFAQ #006.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441