I have a variable called CURRENTDATE=20151105.
I want to create a string as below:
abc_20151105_20151105
I tried the following variations:
echo "abc_$CURRENTDATE_$CURRENTDATE"
This gave abc_20151105
echo "abc_'$CURRENTDATE'_'$CURRENTDATE'"
This gave abc_'20151105'_'20151105'
What am I missing here? Thanks in advance!
CURRENTDATE_variable. Use${CURRENTDATE}_. The second version does exactly what you'd expect which is expand your variables and leave the single quotes intact.echo abc_$CURRENT_DATE\_$CURRENT_DATEI've also found this unix.stackexchange.com/questions/88452/… -- it's worth a read.echo "abc_$CURRENTDATE""_$CURRENTDATE". That said, I use curly braces almost whenever possible, to reduce unknowns. I also prefer printf.printf 'abc_%s_%s\n' "$CURRENTDATE" "$CURRENTDATE"