[英]How to find a substring from some text in a file and store it in a bash variable?
[英]I have some bash scripts. How to store the success or failure of their output into a file?
所以我想知道如何在每个脚本中编写某种命令,如果脚本成功与否,它将 output 并将 append 写入文件。 可能吗?
您可以通过使用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
您可以对文件使用标准错误和标准 output。 例如
echo standard output >> standard_file
echo standard error 2>> standard_error
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.