title: Bash script: save stream from Serial Port (/dev/ttyUSB0) to file until a specific input (e.g. eof) appears
body: <p>I need a bash script to read the data stream from a Serial Port (RS232 to USB adapter - Port: /dev/ttyUSB0). The data should be stored line by line in a file until a specific input (for example "eof") appears. I can give any external input to the Serial Port.
  Till now I use cat to read the data, which works fine.</p>
  
  <pre><code>cat /dev/ttyUSB0 -&gt; file.txt
  </code></pre>
  
  <p>The problem is, that I need to finish the command myself by entering cntr+C, but I don't know exactly when the data stream ends and the ttyUSB0 file does not gerenate an EOF. I tried to implement this myself, but did not find a convenient solution.
  The following command works, but I don't know how to use it for my problem ("world" will create a "command not found" error):</p>
  
  <pre><code>#!/bin/bash
  cat &gt; file.txt &lt;&lt; EOF
  hello
  EOF
  world
  </code></pre>
  
  <p>The following code works for my problem, but it takes too much time (the data stream consists of ~2 million lines):</p>
  
  <pre><code>#!/bin/bash
  while read line; do
       if [ "$line" != "EOF" ]; then
            echo "$line" &gt;&gt; file.txt
       else
            break
       fi
  done &lt; /dev/ttyUSB0
  </code></pre>
  
  <p>Has anyone a convenient possibility for my problem?</p>