Variable not working correctly.

Hi,

I have a script where I am trying to set a local variable using the following,

MYVAR="$NAME"_"$NAME2".txt

where say,

NAME = one
NAME2 = two

so I want the output one_two.txt but what I am getting is,

two.txt

basically the $NAME2 is overwriting, what am I doing wrong?

Thanks,

Works fine with bash.

$ NAME=one
$ NAME2=two
$ MYVAR="$NAME"_"$NAME2".txt
$ echo $MYVAR
one_two.txt
$

You can try the following syntax:

$ MYVAR="${NAME}_${NAME2}.txt"
$ echo $MYVAR
one_two.txt
$

Jean-Pierre.

Try

MYVAR="${NAME}_${NAME2}".txt

On my unix box everytime I use the underbar character "_" I run into trouble
when using it to concatenate two names. The OS reads in the underbar and
looks to the next character, handling it differently.

On one of your replies, someone demonstrated correctly that when you
concatenate, keep the other names plus the underbar character all within
double quotes. That way, the OS will treat the underbar as a literal character instead of (probably) a meta-character.