How to concatenate two strings in Bash
In this tutorial, we are going to learn about how to concatenate two strings in Bash shell.
Concatenation means joining two or more strings together into a single string.
Concatenate strings
To concatenate the two strings into a single string, we can use use +=
operator in the bash.
Here is an example:
name="bash"
name+="shell"
echo "$name"
Output:
bashshell
Similarly, we can also use the below syntax to concatenate strings in Bash.
first="bash"
last="shell"
name="$first$last"
echo "$name"
Output:
bashshell
We can also concatenate by adding space between two strings like this:
name="$first $last"
Output:
bash shell