Portál AbcLinuxu, 14. května 2025 02:15
Řešení dotazu:
trap
trap [COMMANDS] [SIGNALS] This instructs the trap command to catch the listed SIGNALS, which may be signal names with or without the SIG prefix, or signal numbers. If a signal is 0 or EXIT, the COMMANDS are executed when the shell exits.^C je z pohladu shellu len jeden zo signalov. Viac: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_02.html
trap "" 2 20
, takze to sem doplnim, at je tu primo "navod".
#!/bin/sh SIGINT_TRAP_COUNTER=3 handler_signit() { ((SIGINT_TRAP_COUNTER=$SIGINT_TRAP_COUNTER-1)); if [ $SIGINT_TRAP_COUNTER -lt 1 ]; then printf "debug: handler_signit: ending prematurely\n"; exit 1; fi printf "debug: handler_signit: doing cleanup ($SIGINT_TRAP_COUNTER)\n"; sleep 4; # just a fake cleanup time exit 0; } trap handler_signit SIGINT while true ; do printf "main_loop: looping ...\n"; sleep 5; donetakto mas moznost odchytit ^c a davas moznost userovi skoncit ten script, ak to naozaj chce.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.