#!/bin/sh -u # demo script to try two different SIGINT trap lines # # $0 (no arguments) # # Demonstrate how the "trap" command affects scripts and the commands # that are run by scripts. # # NOTE: This script fragment is incomplete - it does not follow all # the script guidelines set out in "script_style.txt". It also # contains many "Instructor-Style" comments that you must not use in # your own scripts. See script_style.txt for details. # # -IAN! idallen@idallen.ca PATH=/bin:/usr/bin ; export PATH LC_COLLATE=C ; export LC_COLLATE LANG=C ; export LANG umask 022 # Un-comment one line to compare how ignoring interrupts works: # - Disabling interrupts entirely means nothing interrupts the script # or any of the commands it runs. # - Giving a trap command string means that commands that the script # executes can be interrupted; but, the script itself will not exit. # trap '' 2 # completely ignore SIGINT # trap 'echo Interrupt!' 2 # script traps SIGINT; commands do not let x=5 while [ $x -gt 0 ] ; do echo "x is $x" let x=x-1 sleep 3 done