linux - 如何检测 bash shell 命令后跟逻辑 && AND 或 ||或者?

标签 linux bash shell

我喜欢为我使用的常用构建命令取一个简短的名称。我也喜欢他们在完成时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 $?

现在,如果您将 bb2 实现为 shell 函数而不是外部命令,您可以做一些内省(introspection) -- 寻找在 BASH_SOURCE 数组中检查代码调用中涉及的堆栈帧——但这非常脆弱,绝不是一个好的做法。

关于linux - 如何检测 bash shell 命令后跟逻辑 && AND 或 ||或者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31798788/

相关文章:

linux - 在 Linux nginx 服务器上发布 ASP.NET Core 应用程序

ios - 将 iOS 应用程序 console.log 重定向到终端

bash - 编辑上一个命令输出的第 n 行的快速方法

java - 在 eclipse 中执行 AWS 命令

perl - 如何找到csv记录的差异

linux - 使用内存映射的IO时调用ioread函数有什么好处

java - 在 2 台 PC 之间创建信任证书

bash - 如何在 bash 循环中组合两个范围?

linux - 向 linux 进程发送信号并拦截它们

linux - 我可以根据头文件 (gcc) 自动查找我在链接时使用的 -l 参数吗?