zsh 中的静默后台作业

7 zsh

我在我的.zshrc中运行archey。问题是,由于显示当前 IP,它有时可能会运行两秒钟。为了让这不那么明显,我把它放在背景中,如下所示:

# .zshrc
archey &
# lots of foo
wait
Run Code Online (Sandbox Code Playgroud)

这样,它可以在我的 zshrc 中完成许多其他工作的同时获取 IP。但是现在 zsh 显示了作业和进程 ID,并且每次都完成了 archey:

Last login: Mon Jul 10 11:12:07 on ttys002
[1] 40436

# archey output

[1]  + done       archey

~
?
Run Code Online (Sandbox Code Playgroud)

正如文档所述,这将被发送到 stderr,我尝试使用 2>/dev/null,但没有成功。

如何删除这两行?

小智 11

Zsh 提供了MONITORNOTIFY选项,您可以禁用它们以使后台作业的状态报告静音。

() {
  setopt LOCAL_OPTIONS NO_NOTIFY NO_MONITOR
  archey &
  # ...
  wait
}
Run Code Online (Sandbox Code Playgroud)

  • 实际上我需要的只是“setopt LOCAL_OPTIONS NO_MONITOR”。除了实际命令之外,其他一切都保持不变 (3认同)