问题原文
原帖链接 · warvariuc · CC BY-SA 3.0
set -x or set -v prints every executed command.
How do I get the command printed with the time when the command started executing?
已采纳解答
原帖链接 · laurent · CC BY-SA 4.0
in Bash, execution of code after each command can be achieved using the "trap" builtin and the "DEBUG" level.
in bash do: help trap or refer to bash manual page, and look for the trap section
example:
trap 'date' DEBUG
This will execute the command "date" juste after each command.
Of course you can format the timestamp as you want, refer to the "date" manual page.
If you want to remove the newline, so that timestamp appears in front of next command, you can do:
trap 'echo -n $(date)' DEBUG
And to terminate this:
trap '' DEBUG
You can combine with "set -x" / "set +x"
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
