Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • thank you, but I want the name of my new var to contain the content of VAR_ONE. I don't want to create _var of any other static name Commented Nov 17, 2023 at 19:50
  • So, I successfully created a var called "newvar${VAR_ONE}". This is my intention. This variable exists, I can verify with env | grep newvar. My challenge is: how do I address this new variable e.g. in an "echo" statement? – Commented Nov 17, 2023 at 19:55
  • the new variable name does contain the content of VAR_ONE, see the last echo which verifies the new variable (named as desired) exists ; in a separate comment you asked how you can go about referencing the newly created variable ... this shows how you can reference that new variable via the nameref, see echo "${_var}" Commented Nov 17, 2023 at 19:57
  • 1
    I'm sorry to take so much of your time. I'm a +60y old engineer who never had any coding class in his life. I am trying to understand, but my 2 brain-cells are boiling now. I understand that last echo... but in my case, I don't know the contents of VAR_ONE (being "thisIsVarOne"). In your last echo, you are using that contents. Commented Nov 17, 2023 at 20:04
  • 1
    re: nameref ... imagine you have 3 brothers (Larry, Moe, Curly), the label brother would be similar to a nameref; if you establish that brother=Moe then you can proceed to reference Moe by the label 'brother' ... brother can you spare a dime, how old are you brother; now suppose you establish that brother=Larry then you can proceed to reference Larry by the label 'brother' ... brother can you spare a dime, how old are you brother; clear as mud? :-) Commented Nov 17, 2023 at 20:16