sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

D1862.INT-in-subshell.sh (760B)


      1 #!/usr/bin/env bash
      2 
      3 # function set_trap { for sig in INT QUIT; do trap "echo $sig >/dev/tty; trap - $sig; kill -$sig $BASHPID" "$sig"; done; }
      4 # function process_something { echo do >/dev/tty; for ((i=0;i<1000000;i++)); do :; done; echo done >/dev/tty; }
      5 
      6 function set_trap {
      7   trap 'echo INT >/dev/tty;trap - INT;kill -INT $BASHPID' INT
      8 }
      9 function process_something {
     10   echo start >/dev/tty
     11   for ((i=0;i<1000000;i++)); do :; done
     12   echo end >/dev/tty
     13 }
     14 
     15 case $1 in
     16 (direct)
     17   set_trap; process_something ;;
     18 (subshell)
     19   (set_trap; process_something) ;;
     20 (comsub)
     21   : $(set_trap; process_something) ;;
     22 (subshell-inherit)
     23   set_trap; (process_something) ;;
     24 (comsub-inherit)
     25   set_trap; : $(process_something) ;;
     26 (comsub-plain)
     27   : $(process_something) ;;
     28 esac