title: Linux shell script, use variable more than once
body: <p>I've created a script that accesses a website with the use of a datafile and outputs the sites responses (one line XML) to an output file. I would like the output to start with the query of the datafile and then the response of the website. When I echo the query one one line and write it to an output file and then write the site's response to the same output file it uses two lines but I only want one line because I would like to end up with a comma separated file that I can import in excel.</p>
  
  <p>This works but with having two lines of data:</p>
  
  <pre><code>while read -r line || [[ -n $line ]]
  do
  datatogather="$line"
  echo $datatogather &gt;&gt;outputfile.txt
  curl http://login:password@somewebsite.info/application.php?$datatogather &gt;&gt;outputfile.txt
  echo &gt;&gt;outputfile.txt
  done &lt; datafile.txt
  </code></pre>
  
  <p>This doesn't work (although it shows the comma in the output file, so that line is being processed):</p>
  
  <pre><code>while read -r line || [[ -n $line ]]
  do
  datatogather="$line"
  echo $datatogather,&gt;&gt;outputfile.txt | curl http://login:password@somewebsite.info/application.php?$datatogather &gt;&gt;outputfile.txt
  echo &gt;&gt;outputfile.txt
  done &lt; datafile.txt
  </code></pre>
  
  <p>Stripping the output file of it's garbage data with sed was a breeze to figure out, even reading the input file into the site was very easy compared to figuring out how to use a variable more than once in a single line. Hope you can help me.</p>