从 bash 脚本获取信息时如何保持冗长

jm_*_*jm_ 5 bash

我需要通过源调用检查 bash 脚本的运行,如下所示:

#!/bin/bash
some code here
source script_b.sh
more code here
Run Code Online (Sandbox Code Playgroud)

我跑:

$bash -x script_a.sh
Run Code Online (Sandbox Code Playgroud)

我得到,

+ some echo here
+ script_b.sh
+ some more echo here
Run Code Online (Sandbox Code Playgroud)

但所有回显都来自 script_a.sh。script_b.sh 中的所有代码都是隐藏的,因此我无法追踪到底发生了什么。

有什么方法可以检查 script_a.sh 中 script_b.sh 的执行情况吗?

gNU*_*.be 3

您可以在父脚本中尝试“bash -x script_b.sh”。

编辑:

这对我有用。如果您使用 bash -x 运行父脚本,您将看到两者的所有内容。“set -x”将在脚本中设置环境的调试标志... 我不确定,fifo 对我来说仍然很神奇。

echo "start of script"
set -x
mkfifo fifo
cat /dev/null < fifo | fifo > source .bash_profile
rm fifo
echo "end of script"
Run Code Online (Sandbox Code Playgroud)