How to concat variable and string in bash script
Nice.
Mac OS X 10.12 works with following ...
#!/bin/bash
var1=bar
var2=foo
var3="$var1"sometext
echo $var3
Result
barsometext
Late for the party, my 2 cents for another solu., also works in zsh
:
i=`date +%d%b`
val1="$i-i-*"
Strings are concatenated by default in the shell.
value="$variable"text"$other_variable"
It's generally considered good practice to wrap variable expansions in double quotes.
You can also do this:
value="${variable}text${other_variable}"
The curly braces are useful when dealing with a mixture of variable names and strings.
Note that there should be no spaces around the =
in an assignment.