EN
Bash - concatenate two string variables
0
points
In this article, we would like to show you how to concatenate string variables in Bash.
Quick solution:
#!/bin/bash
variable_1='text_1'
variable_2='text_2'
result="${variable_1}${variable_2}"
Practical example
In this example, we create a and b variables inside a script.sh file and concatenate them into one - result with space between them. At the end we display the result using echo command.
script.sh file:
#!/bin/bash
a='Hello'
b='World!'
result="$a $b"
echo "$result"
Run in command line:
./script.sh
Output:
Hello World!
Note:
In this case, we don't need curly braces (
{}). They are needed only when we want to limit variable name (explicitly indicate variable name).