title: Read an input file in shell script and store its lines in a variable
body: <p>I'm new to UNIX and have this really simple problem:</p>
  
  <p>I have a text-file (input.txt) containing a string in each line. It looks like this:</p>
  
  <pre><code>House
  Monkey
  Car
  </code></pre>
  
  <p>And inside my shell script I need to read this input file line by line to get to a variable like this:</p>
  
  <pre><code>things="House,Monkey,Car"
  </code></pre>
  
  <p>I know this sounds easy, but I just couldnt find any simple solution for this. My closest attempt so far:</p>
  
  <pre><code>#!/bin/sh
  things=""
  addToString() {
      things="${things},$1"
  }
  while read line; do addToString $line ;done &lt;input.txt
  echo $things
  </code></pre>
  
  <p>But this won't work. Regarding to my google research I thought the while loop would create a new sub shell, but this I was wrong there (see the comment section). Nevertheless the variable "things" was still not available in the echo later on. (I cannot just write the echo inside the while loop, because I need to work with that string later on)</p>
  
  <p>Could you please help me out here? Any help will be appreciated, thank you!</p>