Jotne
January 4, 2013, 7:23am
1
Is there a more simple way to add text to a variable
I have
var="blue"
and like to add green
to get
echo $var
blue green
Here is how I do it.
var=$(echo "${var} green")
---------- Post updated at 13:23 ---------- Previous update was at 13:12 ----------
:o Uff
Not always easy to see the simple...
This works fine
var="${var} green"
RudiC
January 4, 2013, 8:15am
2
in bash:
$ var+=" green"
$ echo $var
blue green
1 Like
Note that the braces aren't needed either unless what you want to add to the variable could be interpreted by the shell to be part of the variable name.
var=blue
echo "$var"
var="$var green"
echo "$var"
var="${var}red"
echo "$var"
produces
blue
blue green
blue greenred