linux - Find signal number by signal name -
i want trap signal sigtstp, simple this:
trap "" sigtstp however, pure shell (sh) not support signal name, trap must use signal number instead, this:
trap "" 20 problem: signal numbers os-dependent, sigtstp in linux 20 in aix it's 18.
so make generic decide extract signal number result of trap -l. raw input is:
1) sighup 2) sigint 3) sigquit 4) sigill 5) sigtrap 6) sigabrt 7) sigemt 8) sigfpe 9) sigkill 10) sigbus 11) sigsegv 12) sigsys 13) sigpipe 14) sigalrm 15) sigterm 16) sigurg 17) sigstop 18) sigtstp 19) sigcont 20) sigchld 21) sigttin 22) sigttou 23) sigio 24) sigxcpu 25) sigxfsz 27) sigmsg 28) sigwinch 29) sigpwr 30) sigusr1 31) sigusr2 32) sigprof 33) sigdanger 34) sigvtalrm 35) sigmigrate 36) sigpre 37) sigvirt 38) sigalrm1 39) sigwaiting 50) sigrtmin 51) sigrtmin+1 52) sigrtmin+2 53) sigrtmin+3 54) sigrtmax-3 55) sigrtmax-2 56) sigrtmax-1 57) sigrtmax 60) sigkap 61) sigretract 62) sigsound 63) sigsak i can't use grep, because feature need, --only-matching, not supported. trap -l | grep -oe "[0-9]+\) sigtstp" | cut -d')' -f1 works well, in linux.
i failed use sed because of greedy problem described here
so trap -l | sed -nr 's/.*([0-9]+)\) sigtstp.*/\1/p' returns 8, not 18
i want make extraction generic possible, won't assume sigtstp double-digit code, when in reality is.
any suggestion?
try constraining match word boundary:
trap -l | sed -nr 's/.*\b([0-9]+)\) sigtstp.*/\1/p'
this tested correctly [for me] target string sigpipe.
Comments
Post a Comment