所以我想知道如何在每个脚本中编写某种命令,这些命令将在脚本成功与否时输出,并将其附加到文件中。有可能吗?
您可以通过使用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