Shell variable names are composed of alphabetic characters, numbers and underscores.
3.231 Name
In the shell command language, a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit.
So when you wrote $A_new
the shell interpreted the underscore (and new
) as part of the variable name and expanded the variable A_new
.
A period is not valid in a variable name so when the shell parsed $A.new
for a variable to expand it stopped at the period and expanded the A
variable.
The ${A}
syntax is designed to allow this to work as intended here.
You can use any of the following to have this work correctly (in rough order of preferability):
echo "${A}_new"
echo "$A"_new
echo $A\_new
The last is least desirable because you can't quote the whole string (or the \
doesn't get removed. So since you should basically always quote your variable expansions you would end up probably doing echo "$A"\_new
but that's no different then point 2 ultimately so why bother.