bash – 源文件如何继承陷阱DEBUG?
发布时间:2020-12-16 01:37:24 所属栏目:安全 来源:网络整理
导读:运行以下代码段: #!/bin/bashfunction preexec (){ echo -e "n--preexec command: $BASH_COMMAND"}trap 'preexec' DEBUGfunction testfunc (){ echo "testfunc called $1"}testfunc "main"source "source.sh"exit 0 其中source.sh是 #!/bin/bashtestfunc "
运行以下代码段:
#!/bin/bash function preexec () { echo -e "n-->preexec command: $BASH_COMMAND" } trap 'preexec' DEBUG function testfunc () { echo "testfunc called $1" } testfunc "main" source "source.sh" exit 0 其中source.sh是 #!/bin/bash testfunc "source" 得到: -->preexec command: testfunc "main" testfunc called main -->preexec command: source "source.sh" testfunc called source -->preexec command: exit 0 这意味着源文件中的每个命令都不会被DEBUG陷阱捕获. trap 'preexec' DEBUG 在source.sh内部作为第二行,一切都按照需要工作(源文件中的命令也被捕获). 如何将此作为默认行为,以避免为我需要提供的任何文件重复上述行?
我解决了主文件中的设置:
set -o functrace 来自BASH的人:
作为’source’的shell函数,它们是继承的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |