To concatenate string variables in Bash, simply use the = operator without spaces. You can directly place variables or strings next to each other. Here’s an example:
#!/bin/bash
str1=”Hello”
str2=”World”
result=”${str1} ${str2}” # Using braces for clarity and adding a space
echo “$result”
Alternatively, concatenate strings by appending text to an existing variable:
str=”Hello”
str+=” World” # Adds to the existing variable
echo “$str”
Always use double quotes to preserve spaces or special characters during concatenation. This ensures the strings are combined correctly without issues.