Linux的巴什 - 捕捉-x调试命令到一个文件 [英] Linux Bash - capture -x debug commands into a file
本文介绍了Linux的巴什 - 捕捉-x调试命令到一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用设置-x
在bash打印外壳扩展命令标准错误。
我想这些重定向到文件或管道。
而不是整个输出 - 只有一些命令。
是这样的:
Using set -x
in bash prints the shell-expanded commands to stderr.
I would like to redirect these to a file or pipe.
But not the whole output - only some commands.
Something like:
set -x command.txt ### <-- command.txt param is made up
echo $A $B
set +x
这将使调试输出命令。 TXT。
This would put the debug output to command. txt.
可以这样做?
推荐答案
通过庆典
4.1或更高版本:
With bash
4.1 or later:
#!/bin/bash
exec 5> command.txt
BASH_XTRACEFD="5"
echo -n "hello "
set -x
echo -n world
set +x
echo "!"
输出到标准输出(FD 1):
Output to stdout (FD 1):
hello world!
输出到command.txt(FD 5):
Output to command.txt (FD 5):
+ echo -n world
+ set +x
这篇关于Linux的巴什 - 捕捉-x调试命令到一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文