I have the following code that runs in a shell script
foo=`seq 1 1 100`
for i in $foo; do
echo "input$i\_now"
done
Here's my question: Under some conditions, the output prints input1_now whereas othertimes it prints input1\_now. I'm sure something is different, but I can't figure out what makes it print one way or the other. If my code is
for i in $foo; do
echo "input$i_now"
done
I will always get input with the rest of the line being omitted.
I know I can use input${i}_now instead and have it print correctly every time, but I'm mostly interested in understanding why the output is different under seemingly the same conditions.
UPDATE:
In the following example, the first part correctly formats the variables and text such that the \_ is replaced as _. However, the last part required me to place variables in curly brackets in order to have them formatted correctly.
echo "Enter Simulation #: "
read sim
g.mapset results
for i in `seq 1 1 100`; do
file=sim$sim\_run$i\_sum
g.copy $file\@expSim$sim\_$i,$file
file=sim$sim\_run$i\_average
g.copy $file\@expSim$sim\_$i,$file
for year in `seq 2004 1 2006`; do
file=sim$sim\_$year\_run$i\_sum
g.copy $file\@expSim$sim\_$i,$file
file=sim$sim\_$year\_run$i\_average
g.copy $file\@expSim$sim\_$i,$file
done
years="2004 2005 2006"
times=`seq -w 1 16 365`
runs=`seq 1 1 100`
for year in $years; do
for ptime in $times; do
for i in $runs; do
if [ $i -eq 1 ]; then
g.copy vect=sim${sim}_pts_${year}_${ptime}_run${i}@expSim${sim}_${i},sim${sim}_pts_${year}_${ptime}
fi
if [ $i -gt 1 ]; then
v.patch input=sim${sim}_pts_${year}_${ptime}_run${i}@expSim${sim}_${i} output=sim${sim}_pts_${year}_${ptime} -e -a --o
fi
done
done
done
inputx\_nowconsistently for me.