title: string formatting in bash
body: <p>I have the following code that runs in a shell script</p>
  
  <pre><code>foo=`seq 1 1 100`
  for i in $foo; do
    echo "input$i\_now"
  done
  </code></pre>
  
  <p>Here's my question:  Under some conditions, the output prints <code>input1_now</code> whereas othertimes it prints <code>input1\_now</code>.  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</p>
  
  <pre><code>for i in $foo; do
     echo "input$i_now"
  done
  </code></pre>
  
  <p>I will always get <code>input</code> with the rest of the line being omitted.</p>
  
  <p>I know I can use <code>input${i}_now</code> 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.</p>
  
  <p>UPDATE:</p>
  
  <p>In the following example, the first part correctly formats the variables and text such that the <code>\_</code> is replaced as <code>_</code>.  However, the last part required me to place variables in curly brackets in order to have them formatted correctly.</p>
  
  <pre><code>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
  </code></pre>