Last modified (UTC) $Date: 2020/08/05 04:27:36 $

MEMO > FreeBSD > シェルスクリプト trapサンプル

#!/bin/sh -eu

LOOP_FLAG=1

trap finally EXIT
trap catch_intr 2

finally() {
    echo "finally"
}
catch_intr() {
    LOOP_FLAG=0
}

while [ $LOOP_FLAG -eq 1 ]; do
    date
    sleep 1
done