击:在执行前打印每个命令? [英] Bash: Print each command before executing?
问题描述
什么是设置,打印每个命令在执行之前,bash脚本的最佳方式?
这将是伟大的进行调试。
我已经尝试过这样的:
CMD =./我的命令--params> stdout.txt 2 - ;的stderr.txt
回声$ CMD
`$ CMD`
什么它应该做的是打印这首:
./我的命令--params> stdout.txt 2 - ;的stderr.txt
,然后执行 ./我的命令--params
,以重定向到文件的输出指定。
设置-o X跟踪
或
的bash -x myscript.sh
的这适用于标准的/ bin / sh的还有IIRC(这可能是一个POSIX的事情的话)的
记住,还有 bashdb ( bash shell的调试,释放4.0- 0.4
)
要恢复正常,退出子shell或
组+ O X跟踪
What is the best way to set up a bash script that prints each command before it executes it?
That would be great for debugging purposes.
I already tried this:
CMD="./my-command --params >stdout.txt 2>stderr.txt"
echo $CMD
`$CMD`
What it's supposed to do is to print this first:
./my-command --params >stdout.txt 2>stderr.txt
and then execute ./my-command --params
, with the output redirected to the files specified.
set -o xtrace
or
bash -x myscript.sh
This works with standard /bin/sh as well IIRC (it might be a POSIX thing then)
And remember, there is bashdb (bash Shell Debugger, release 4.0-0.4
)
To revert to normal, exit the subshell or
set +o xtrace
这篇关于击:在执行前打印每个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!