new traps example

This commit is contained in:
2025-02-08 13:21:31 +08:00
parent 8da2059d1e
commit 3696cc06af

21
helpers/traps.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
#TODO source basic.sh
#TODO source args-parser/args.sh
########################################################
# Trap usage examples
########################################################
# for sig in SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGTERM SIGTSTP; do
# # shellcheck disable=SC2064
# trap "set +x && echo && echo && echo '*** Прервано сигналом $sig, остановка ***' && exit" $sig
# done
for sig in SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGTERM SIGTSTP; do
trap "myfunc" $sig
done
myfunc() {
echo "trapped!"
exit
}