********* Scripting ********* Templates I use in my scripts. Reacting to Ctrl+c (SIGINT) with trap ===================================== .. code-block:: bash control_c() { echo # new line for ^C character that is printed echo "Exiting." exit 1 } trap control_c SIGINT or doing something in any case: .. code-block:: bash #!/bin/bash set -e finally() { echo finally } trap finally EXIT echo before error false # change me to true and see what happens echo after error Looping Directories Containing Whitespace ========================================= .. code-block:: bash IFS=$'\n' dirs=$(ls /tmp) for dir in $dirs; do echo $dir done