Shell variable inside variable

user2230605

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,

Charles Duffy

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Shell variable inside variable

From Dev

awk variable inside a shell function

From Dev

Modify a shell variable inside awk block of code

From Dev

Exporting a Path Variable inside a shell script

From Dev

Shell Script: creating a variable with options inside

From Dev

Exporting a Path Variable inside a shell script

From Dev

Use shell variable inside a pattern in awk

From Dev

my shell script inside shell script not getting int variable

From Dev

Get a variable in a variable in shell

From Dev

Get a variable in a variable in shell

From Dev

Resolve Variable in a Variable in shell

From Dev

Echo a variable inside a variable

From Dev

Variable inside a variable in a loop

From Dev

Using variable inside variable

From Dev

A variable inside an another variable

From Dev

Using sed on xargs variable isn't working inside shell expansion

From Dev

TCSH Shell Script: substitute a variable using sed inside file

From Dev

Spaced string variable as command parameter inside shell script

From Dev

reference shell variable $COLUMNS from inside a bash script

From Dev

Trying to use Applescript variable in curl command inside do shell script

From Dev

Unable to get the accurate value of shell variable set inside a pipe

From Dev

Most defensive/robust way of unsetting an environment variable inside a shell script

From Dev

Variable won't get expanded when INSIDE mysql shell

From Dev

How to retain the value of a variable inside for loop in shell script

From Dev

How to escape a special character that is hidden inside variable in unix shell script

From Dev

Change Shell script variable value inside AWK conditional block

From Dev

How to use a shell variable inside sed when doing "d" command?

From Dev

How to use {old,new}name inside a shell script variable?

From Dev

get the values stored in OPTARG variable inside a shell script

Related Related

  1. 1

    Shell variable inside variable

  2. 2

    awk variable inside a shell function

  3. 3

    Modify a shell variable inside awk block of code

  4. 4

    Exporting a Path Variable inside a shell script

  5. 5

    Shell Script: creating a variable with options inside

  6. 6

    Exporting a Path Variable inside a shell script

  7. 7

    Use shell variable inside a pattern in awk

  8. 8

    my shell script inside shell script not getting int variable

  9. 9

    Get a variable in a variable in shell

  10. 10

    Get a variable in a variable in shell

  11. 11

    Resolve Variable in a Variable in shell

  12. 12

    Echo a variable inside a variable

  13. 13

    Variable inside a variable in a loop

  14. 14

    Using variable inside variable

  15. 15

    A variable inside an another variable

  16. 16

    Using sed on xargs variable isn't working inside shell expansion

  17. 17

    TCSH Shell Script: substitute a variable using sed inside file

  18. 18

    Spaced string variable as command parameter inside shell script

  19. 19

    reference shell variable $COLUMNS from inside a bash script

  20. 20

    Trying to use Applescript variable in curl command inside do shell script

  21. 21

    Unable to get the accurate value of shell variable set inside a pipe

  22. 22

    Most defensive/robust way of unsetting an environment variable inside a shell script

  23. 23

    Variable won't get expanded when INSIDE mysql shell

  24. 24

    How to retain the value of a variable inside for loop in shell script

  25. 25

    How to escape a special character that is hidden inside variable in unix shell script

  26. 26

    Change Shell script variable value inside AWK conditional block

  27. 27

    How to use a shell variable inside sed when doing "d" command?

  28. 28

    How to use {old,new}name inside a shell script variable?

  29. 29

    get the values stored in OPTARG variable inside a shell script

HotTag

Archive