title: How to use Ctrl+C to stop whole script not just current command
body: <p>I have a script such as follows:</p>
  
  <pre><code>for ((i=0; i &lt; $srccount; i++)); do
      echo -e "\"${src[$i]}\" will be synchronized to \"${dest[$i]}\""
      echo -e $'Press any key to continue or Ctrl+C to exit...\n' 
      read -rs -n1
      rsync ${opt1} ${opt2} ${opt3} ${src[$i]} ${dest[$i]}
  done
  </code></pre>
  
  <p>If I press <kbd>Ctrl</kbd>+<kbd>C</kbd> in response to read command, the whole script will stop, but if press <kbd>Ctrl</kbd>+<kbd>C</kbd> while <code>rsync</code> command is running, just current <code>rsync</code> command will stop and the script will continue the for loop.</p>
  
  <p>Is there any way to tell the script if the user pressed <kbd>Ctrl</kbd>+<kbd>C</kbd> while <code>rsync</code> is running, stop <code>rsync</code> and exit from the script itself?</p>