我喜欢为我使用的常用构建命令取一个简短的名称。我也喜欢他们在完成时notify-send
我,这样我就可以在等待的同时处理多项任务,而不用看终端。
现在,我希望命令在链接它们时不发出通知。例如
alias b='command and parameters for my build; notify-send'
alias b2='command and parameters for a second type of build; notify send'
$ b
// I am notified when it completes, just once.
$ b && b2
// Today, I am notified twice, when b completes and when b2 does.
// I would like to only be notified when they all complete.
// (and I would rather not type b && b2 && notify-send)
那么,在 bash 中,命令能否检测到它们后跟 &&
或 ||
?
最佳答案
没有。一般的答案是将通知移到命令之外:
b && b2; notify-result $?
现在,如果您将 b
和 b2
实现为 shell 函数而不是外部命令,您可以做一些内省(introspection) -- 寻找在 BASH_SOURCE
数组中检查代码调用中涉及的堆栈帧——但这非常脆弱,绝不是一个好的做法。
关于linux - 如何检测 bash shell 命令后跟逻辑 && AND 或 ||或者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31798788/