#!/bin/bash -x
echo This is a script that has debugging turned on
Run Code Online (Sandbox Code Playgroud)
此脚本输出
+ echo This is a script that has debugging turned on
This is a script that has debugging turned on
Run Code Online (Sandbox Code Playgroud)
我想通过删除或替换它们来摆脱这些 +。我希望 sed 可以解决我的问题 ( sed 's/^\++//g'
) -- 但这种方法不会影响调试输出行。
通过更多的实验,我发现调试输出似乎被写入 stderr(用./test.sh 2>/dev/null
输出然后排除调试行的命令推断出这一点)
有了这些新信息,我希望这能奏效
./test.sh 2>&1 | sed 's/^\++//g'
但是,唉,我仍然得到相同的不想要的输出:
+ echo This is a script that has debugging turned on
This is a script that has debugging turned on
Run Code Online (Sandbox Code Playgroud)