<> == How can I concatenate two variables? How do I append a string to a variable? == There is no (explicit) concatenation operator for strings (either literal or variable dereferences) in the shell; you just write them adjacent to each other: {{{#!highlight bash var=$var1$var2 }}} If the right-hand side contains whitespace characters, it needs to be quoted: {{{#!highlight bash var="$var1 - $var2" }}} If you're appending a string that doesn't "look like" part of a variable name, you just smoosh it all together: {{{#!highlight bash var=$var1/.- }}} Otherwise, braces or quotes may be used to disambiguate the right-hand side: {{{#!highlight bash var=${var1}xyzzy # Without braces, var1xyzzy would be interpreted as a variable name var="$var1"xyzzy # Alternative syntax }}} CommandSubstitution can be used as well. The following line creates a log file name {{{logname}}} containing the current date, resulting in names like e.g. {{{log.2004-07-26}}}: {{{#!highlight bash logname="log.$(date +%Y-%m-%d)" }}} There's no difference when the variable name is reused, either. A variable's value (the string it holds) may be reassigned at will: {{{#!highlight bash string="$string more data here" }}} Concatenating arrays is also possible: {{{#!highlight bash var=( "${arr1[@]}" "${arr2[@]}" ) }}} Bash 3.1 has a new += operator that you may see from time to time: {{{#!highlight bash string+=" more data here" # EXTREMELY non-portable! }}} It's generally best to use the portable syntax. ---- CategoryShell