我有一些bash脚本.如何将其输出的成功或失败存储到文件中



所以我想知道如何在每个脚本中编写某种命令,这些命令将在脚本成功与否时输出,并将其附加到文件中。有可能吗?

您可以通过使用trap来实现这一点-https://www.linuxjournal.com/content/bash-trap-command

在bash文件中添加此命令

# add these lines at the top of your bash script
echo success > your_output_file
trap 'echo failed > your_output_file' ERR

您可以对文件使用标准错误和标准输出。例如

echo standard output >> standard_file
echo standard error 2>> standard_error

最新更新