gpt4 book ai didi

bash - 如何在 shell 脚本中记录带有时间戳的 echo 语句

转载 作者:行者123 更新时间:2023-12-04 16:16:52 26 4
gpt4 key购买 nike

我目前正在使用以下内容来记录 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com