相关疑难解决方法(0)

除非非零退出代码,否则禁止输出

除非程序以非零代码退出,否则抑制输出(stdout 和 stderr)的最佳方法是什么?我在想:

quiet_success()
{
  file=$(mktemp)
  if ! "$@" > "$file" 2>&1; then
    cat "$file"
  fi
  rm -f "$file"
}
Run Code Online (Sandbox Code Playgroud)

并运行,quiet_success my_long_noisy_script.sh但我不确定是否有更好的方法。我觉得这必须是其他人需要做的事情。

对于上下文,我希望将其添加到我的 cron 脚本中,以便在失败时通过电子邮件发送所有内容,但如果失败则不会。

cron io-redirection shell-script

19
推荐指数
2
解决办法
5835
查看次数

标签 统计

cron ×1

io-redirection ×1

shell-script ×1