如何让bash subshell继承父项的set选项? [英] How to let bash subshell to inherit parent's set options?
本文介绍了如何让bash subshell继承父项的set选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在脚本"a.sh"中进行了 set -x
设置,它调用了另一个脚本"b.sh".
Let’s say I do set -x
in a script "a.sh", and it invokes another script "b.sh".
是否可以让"b.sh"继承"a.sh"的 -x
选项?
Is it possible to let "b.sh" inherit the -x
option from "a.sh"?
推荐答案
Export SHELLOPTS
from the parent and all scripts invoked from it will inherit its flags.
$ cat ./foo
#!/bin/bash -
export SHELLOPTS
set -x
./bar
$
$ cat ./bar
#!/bin/bash -
set -o | grep xtrace
$
$ ./foo
+ ./bar
+ set -o
+ grep xtrace
xtrace on
这篇关于如何让bash subshell继承父项的set选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文