Search code examples
linuxbashvariablesterminal

How can I add the value of a second variable to the name of one variable in bash


When i try create new variable with value in the another variables name in bash, I'm failing

]$ xxx=xxx
]$ echo $xxx
xxx

but when i try this:
]$ yyy_${xxx}=yyy
-bash: yyy_xxx=yyy: command not found

or

]$ yyy_$(${xxx})=yyy
-bash: xxx: command not found

or

]$ yyy_$(echo ${xxx})=yyy
-bash: yyy_xxx=yyy: command not found

Please tell me how can I solve this issue? Thanks!


Solution

  • The issue was resolved:

    declare yyy_$(echo ${xxx})=yyy
    

    or

    declare yyy_$(${xxx})=yyy
    

    it works!