简体   繁体   English

将 bash 跟踪(set -x)传播到所有子脚本

[英]Propagate bash tracing (set -x) to all child scripts

How do I propagate bash tracing ( set -x ) to all child scripts without modifying the main script code?如何在不修改主脚本代码的情况下将 bash 跟踪( set -x )传播到所有子脚本? Is there such a way?有这样的方法吗? Maybe an hidden environment variable?也许是隐藏的环境变量?

Let's assume I have:让我们假设我有:

main.sh

#!/bin/bash
echo "Main script"
./child.sh

child.sh

#!/bin/bash
echo "child script"

I want to call main.sh with some flag/environment variable/whatever that will cause child.sh to run with set -e without changing any code我想用一些标志/环境变量/任何会导致child.sh在不更改任何代码的情况下使用set -e运行的东西调用main.sh

I accomplished this task by creating a file $HOME/.bash_env like:我通过创建一个文件$HOME/.bash_env来完成这个任务,如:

set -x

Then I added然后我加了

export BASH_ENV=$HOME/.bash_env

to .bash_rc ..bash_rc

So, each scripts will get bash tracing enabled.因此,每个脚本都将启用 bash 跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM