I want to create a variable from multiple variables by concatenating their values. After that I want to update value in those nested child variables and see the change in the parent one. Something like this:
#!/bin/bash
a=123
b=abc
c=$a$b
echo $c # outputs 123abc
a=456
echo $c # outputs 123abc although I want 456abc
I'd like this to output 123abc and 456abc but instead I get 123abc and 123abc. Is it possible to achieve the behaviour I want in bash?
c=$a$b, you're not assigning references ofaandbtoc, but you're assigning their values.c() { echo "$a$b"; }and use it as$(c)in your script and you will get updated values all the time.