我目前正在使用以下内容来记录 stdout 和 stderr。我想记录 echo 语句和时间戳。
exec 3>&1 1>>${LOG_FILE} 2>&1
如何使用shell实现
最佳答案
根据您可能需要的确切预期行为 ts
效用。
% echo message | ts
Apr 16 10:56:39 message
您还可以为 echo
起个别名。
% sh
$ alias echo='echo $(date)'
$ echo message
Mon Apr 16 10:57:55 UTC 2018 message
或者让它成为一个 shell 函数。
#!/bin/sh
echo() {
command echo $(date) "$@"
}
echo message
关于bash - 如何在 shell 脚本中记录带有时间戳的 echo 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49851882/