Portál AbcLinuxu, 1. listopadu 2025 17:04
skript; moje_funkce()
#!/bin/bash
function finish {
# Your cleanup code here
}
trap finish EXIT
A zlepši hledání, ani na jednu z otázek jsem neznal odpověď, ale během minuty ji našel
Bylo to nějak jako by obalené v nějakém sandboxu, který to poznal...No a proč to nemůže být spuštěné v shellu jak jsem navrhoval?
trap [-lp] [[arg] sigspec ...]
The command arg is to be read and executed when the shell receives signal(s) sigspec.
trap clean_up SIGHUP SIGINT SIGKILL ERR EXIT
function brm {
echo "It's a TRAP!"
}
trap brm SIGHUP SIGINT SIGKILL ERR EXIT
sleep 60
/tmp> bash test.sh &
[1] 19153
/tmp> kill -TERM $!
It's a TRAP!
/tmp>
[1]+ Terminated bash test.sh
/tmp> bash test.sh &
[1] 19173
/tmp> kill -KILL $!
/tmp>
[1]+ Killed bash test.sh
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.