title: Stop avconv Bash script on user input and continue loop
body: <p>Basically (hopefully) I want to record a video stream from a webcam and save it in a specific directory, then kill that when a user inputs some numbers. I'm not explaining this well so here's what I'm doing currently:</p>
  
  <pre><code>#!/bin/bash
  
  while true
  do
  
  TIMESTAMP=$(date +"%Y.%m.%d_%H.%M")
  
  read -p "Enter your number here: " YOURNUMBER
  
  echo -e "Saving video stream:"
  
  mkdir /home/$USER/orders/$YOURNUMBER
  
  avconv -f video4linux2 -r 3 -fs 52428800 -i /dev/video0 /home/$USER/orders/$YOURNUMBER/$TIMESTAMP-$YOURNUMBER.avi
  
  echo -e "Video complete!"
  
  done
  </code></pre>
  
  <p>So I want to stop the recording and start a new on in the new $YOURNUMBER folder. Any ideas? (Quite new to this..be patient!)</p>
  
  <p>Update:</p>
  
  <p>Thanks to @TrueY</p>
  
  <p>Updated script (don't need to mkdir really so taken that out):</p>
  
  <pre><code>CPID=0
  while :; do
    read -p "Enter your number here: " YOURNUMBER
    [ $CPID -ne 0 ] &amp;&amp; kill -INT $CPID
    TIMESTAMP=$(date +"%Y.%m.%d_%H.%M")
    avconv -f video4linux2 -r 3 -fs 52428800 -i /dev/video0 /home/$USER/orders/$YOURNUMBER[packed-$TIMESTAMP].avi &gt; /dev/null 2&gt;&amp;1 &amp;
    CPID=$!
  done
  </code></pre>
  
  <p>Only trouble is that I (or the end user) has to enter the number twice before it starts recording it again..</p>