PDA

View Full Version : bash : string variable replacement



dens57
January 9th, 2007, 04:13 PM
Hello,

I have this :

VAR2='test2
VAR1='test1 $VAR2 test3'
echo $VAR1

the result is : test1 $VAR2 test3

but I would like to have : test1 test2 test3

I'm not a bash expert, it will be really great !

thanks

gpolo
January 9th, 2007, 04:19 PM
you need to use " " instead of ' '

Tomosaur
January 9th, 2007, 04:19 PM
Try this instead:
VAR2="test2"
VAR1="test1 $VAR2 test3"
echo $VAR1

The single quotation tells Bash to leave it alone, so it won't use the variable, it'll treat the variable name as a string.

dens57
January 9th, 2007, 04:38 PM
Thanks a lot, it works fine.