Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从bash脚本获取资源时如何保持冗长_Bash - Fatal编程技术网

从bash脚本获取资源时如何保持冗长

从bash脚本获取资源时如何保持冗长,bash,Bash,我需要检查bash脚本的运行情况,以及源代码调用,类似于: #!/bin/bash some code here source script_b.sh more code here 我运行: $bash -x script_a.sh 我得到 + some echo here + script_b.sh + some more echo here 但所有的回音都来自脚本。脚本_b.sh中的所有代码都是隐藏的,因此我无法跟踪实际发生的情况 有什么方法可以检查script_a.sh中script

我需要检查bash脚本的运行情况,以及源代码调用,类似于:

#!/bin/bash
some code here
source script_b.sh
more code here
我运行:

$bash -x script_a.sh
我得到

+ some echo here
+ script_b.sh
+ some more echo here
但所有的回音都来自脚本。脚本_b.sh中的所有代码都是隐藏的,因此我无法跟踪实际发生的情况

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

您可以在父脚本中尝试“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"
echo“脚本开始”
集合x
mkfifo-fifo
cat/dev/nullsource.bash_配置文件
rm fifo
回显“脚本结束”

它可以根据您的需要为我工作。我正在使用bash 3.2.48。@Barmar谢谢,我的操作系统更高版本。我试着用一个简单的脚本来重现这个问题,它确实有效。奇怪。我将遵循下面的提示。我刚刚在Bash4.1.5中尝试过它,它也起到了作用。这可能会在一个子shell中运行脚本时得到回答。通常你编写一个脚本源代码是因为你需要它来改变原始shell的环境。是的,但是对于调试来说,这可能是一种很难看到发生了什么的方法。使用“strace./script_a.sh”怎么样?