trap.sh | trap (CTRL-C) is signal 2 (SIGINT)

 cat trap.sh
#!/bin/usr/env bash

trap 'increment' 2

increment()
{
  echo "Caught SIGINT ..."
  X=`expr ${X} + 500`
  if [ "${X}" -gt "2000" ]
  then
    echo "Okay, I'll quit ..."
    exit 1
  fi
}

### main script
X=0
while :
do
  echo "X=$X"
  X=`expr ${X} + 1`
  sleep 1
done

Here is a table of some of the common interrupts:
NumberSIGMeaning
00On exit from shell
1SIGHUPClean tidyup
2SIGINTInterrupt
3SIGQUITQuit
6SIGABRTAbort
9SIGKILLDie Now (cannot be trap'ped)
14SIGALRMAlarm Clock
15SIGTERMTerminate

Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all