When I am running two while loop and trying to concatenating two variable strings (from two loops), the final output (string) is weird. I have tried different way to concatenating but did not get the answer: Below is the code:
[I need vfile="var1_Amon_My_model1*.nc"
]
#!/bin/bash
jcount=1
extn="*.nc"
while read line
do
mname=$line
echo " Working on model - " $mname
echo " and model number = "$jcount
while read line
do
vname=$line
vfile="${vname}""_Anom_""${mname}""${extn}"
echo $vfile
done<varlists.txt
echo "******************************************"
jcount=$((jcount+1))
done<model_test1.txt
In varlists.txt
var1
var2
In model_test1.txt
My_model1
My_model2
After executing the script, it is showing
Working on model - My_model1
and model number = 1
*.ncm_My_model1
*.ncm_My_model1
******************************************
varlists.txt
andmodel_test1.txt
, and of the script output? Usehexdump -C
.printf "%q\n" "$vfile"