Concatenation of strings is the most common process when working with string. In Bash, you can concatenate string variables using the concatenation operator + or by simply putting them next to each other.
Without using the concatenation operator +:
str1="Hello"
str2="World"
concatenated_str=$str1$str2
echo $concatenated_str
The output will be:
HelloWorld
Using the concatenation operator +:
str1="Hello"
str2="World"
concatenated_str=$str1+$str2
echo $concatenated_str
The output will be:
HelloWorld
Note that if you want to include a space between the strings, you need to add it explicitly, like this:
str1="Hello"
str2="World"
concatenated_str="$str1 $str2"
echo $concatenated_str
The output will be:
Hello World
Comments (0)