Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在寻找一种将 bash 脚本的每个输出重定向到日志文件的方法,但我希望它在脚本中。
我不喜欢 myScript.sh > logfile
我想要一些可以插入脚本开头的 bash 命令。
谢谢。
您可以将此行放在脚本顶部:
#!/bin/bash exec &> out.log # rest of your script
这会将所有 STDOUT 和 STDERR 从您的脚本重定向到一个文件out.log,此后不需要使用每个命令的重定向。
out.log
检查这个也可以快速重定向任何指南。
tags