Concatenate Strings in Bash
To Concatenate Strings in Bash, use one of the following techniques.
Technique 1 – Using += : Append to variable
Appending str2 to str1. [str1 = str1 + str2]
~$ str1="Learn" ~$ str2=" Bash Scripting" ~$ str1+=$str2 ~$ echo $str1 Learn Bash Scripting
Technique 2 – Keep two string variables side by side
~$ str1="Learn" ~$ str2=" Bash Scripting" ~$ str3=$str1$str2 ~$ echo $str3 Learn Bash Scripting
Technique 3 – Use a string variable in another string
~$ str1="Learn" ~$ str2="$str1 Bash Scripting" ~$ echo $str2 Learn Bash Scripting
Conclusion
In this Bash Tutorial, we have learnt different ways to concatenate strings in Bash Scripting.