[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SIGINT in a sourced script does not clean up some special variables
From: |
Grisha Levit |
Subject: |
SIGINT in a sourced script does not clean up some special variables |
Date: |
Tue, 10 Nov 2015 00:36:15 -0800 (PST) |
User-agent: |
G2/1.0 |
Apologies if I'm missing something about the expected SIGINT behavior. I've
read through the previous SIGINT discussions but this still seems unexpected:
$ declare -p BASH_ARGC BASH_ARGV BASH_SOURCE BASH_LINENO
declare -a BASH_ARGC=()
declare -a BASH_ARGV=()
declare -a BASH_SOURCE=()
declare -a BASH_LINENO=()
$ source <(echo 'kill -INT $$')
$ declare -p BASH_ARGC BASH_ARGV BASH_SOURCE BASH_LINENO
declare -a BASH_ARGC=([0]="1")
declare -a BASH_ARGV=([0]="/dev/fd/63")
declare -a BASH_SOURCE=([0]="/dev/fd/63")
declare -a BASH_LINENO=([0]="5")
Additionally, FUNCNAME is not cleared in some cases:
$ declare -p FUNCNAME
declare -a FUNCNAME
$ source <(echo 'die() { kill -INT $$; }; die')
$ declare -p FUNCNAME
declare -a FUNCNAME
$ source <(echo 'die() { : && kill -INT $$; }; die')
$ declare -p FUNCNAME
declare -a FUNCNAME=([0]="source")
If the sourced script is running a foreground command then these values are
returned back to their initial state after the shell receives a SIGINT -- so I
suspect it's possible to do the same in the cases above.
- SIGINT in a sourced script does not clean up some special variables,
Grisha Levit <=