}

How can I concatenate strings in Bash?

Created:

Introduction

When starting to use bash some string operations could be trickier even if you have experience with other lenguages.

Concatenation example with bash

The following bash script will echo "Word Concatenated" and then "testworld"

tutorial="Word" 
tutorial="$tutorial Concatenated" 
echo $tutorial 
a="test"
b="world"
tutorial=$a$b
echo $tutorial

In the example above we first show how to concatenate an string with a variable. On the second example we show how to concatenate two string variables.

Concatenation using operator +

You can also use the operator +=, let's see some examples:

tutorial="Test"
tutorial+= " World"
echo $tutorial

The examle above will echo "Test World"