buzzin buzzin - 6 months ago 19
Bash Question

echo command with variable and string

I have 3 variables, im trying to insert them into an echo command that contains string as well. Here is what I have.

1= "test1"
2= "test2"
3= "test3"

FileName= "WEATHERMAP"_"$1"_"STATE"_"$2"_"CITY"_"$3"

echo $FileName


I want it to
echo WEATHERMAP_test1_STATE_test2_CITY_test3

Instead I get
WEATHERMAP__STATE__CITY_


I know this has something to do with the
underscore
, unfortunately I need the
underscore
. Only examples I have seen are putting two variables together, or it started with a
variable
followed by string.

Answer

Don't start variable names with a number.

$ a="test1"
$ b="test2"
$ c="test3"
$ FileName="WEATHERMAP_${a}_STATE_${b}_CITY_${c}"
$ echo "$FileName"
WEATHERMAP_test1_STATE_test2_CITY_test3
$
Comments