In PHP, strings are concatenated together as follows:
$foo = "Hello"; $foo .= " World";
Here, $foo
becomes "Hello World".
How is this accomplished in Bash?
The += Operator in Bash Bash is a widely used shell in Linux, and it supports the '+=' operator to concatenate two variables. As the example above shows, in Bash, we can easily use the += operator to concatenate string variables.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.
foo="Hello" foo="${foo} World" echo "${foo}" > Hello World
In general to concatenate two variables you can just write them one after another:
a='Hello' b='World' c="${a} ${b}" echo "${c}" > Hello World
Bash also supports a +=
operator as shown in this code:
A="X Y" A+=" Z" echo "$A"
output
X Y Z
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With