Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to concatenate two strings in bash, so that:



echo mystring should produce


share|improve this question
Terminal command join could also do the thing for you. – Masi Apr 19 '15 at 8:07
up vote 23 down vote accepted

simply concatenate the variables:

share|improve this answer

You don't need to use {} unless you're going to use bash variable parameters or immediate append a character that would be valid as part of the identifier. You also don't need to use double quotes unless you parameters will include special characters.

z=$x$y        # $z is now "foobar"
z="$x$y"      # $z is still "foobar"
z="$xand$y"   # does not work
z="${x}and$y" # does work, "fooandbar"
z="$x and $y" # does work, "foo and bar"
share|improve this answer

In case you need to concatenate variables with literal strings:

mystring="some ${string1} arbitrary ${string2} text"

echo $mystring will produce:

some hello arbitrary world text

share|improve this answer
You can use the ${var} format any time you like, but you only need it when $var is to be immediately followed by another valid variable-name character... eg: $vararbitary will interpret a variable named "vararbitary", but you can get around it by using ${var}arbitary .... oops, I just saw khamer's abswer.. but I may as well leave the comment here. – Peter.O Mar 29 '11 at 15:32

If you want to concatenate a lot of variables you can also use += to append strings.. This may increase readability..

echo ${mystring}

As mentioned by other answers the {} are not needed here but I personally always use them to avoid some syntax errors.

+= can also be used to append values to arrays: array+=($b).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.