I am using read to make some file in a while loop. The code is:
while read var val
do
sed -i 's/$var/$val/g' Hhh300_4L_gen.sh
echo $var $val
done < "Hhh300_4L_config.txt"
Where in Hhh300_4L_config.txt, there is a line, for instance,
PROCESSNAME Hhh;
and in Hhh300_4L_gen.sh, there is one element: PROCESSNAME. So if it works, PROCESSNAME in Hhh300_4L_gen.sh should be replaced by Hhh. But it doesn't. However the output of echo prints correctly.
's/$var/$val/g'->"s/$var/$val/g", otherwise your variable references won't be expanded.sedchoke on a line, try addingset -xto the script before the loop so you can see what the commands look like after the variables are expanded. Then you can find the value that is causing the problem--probably one that has/in it is my guess.txtfile?#then you could use that as theseddelimeter:sed -i "s#$var#$val#g'you don't have to use/if there's something that works better for you