簡體   English   中英

如何檢測bash shell命令后面是否為邏輯&& AND或|| 要么?

[英]How to detect if bash shell command is followed by a logical && AND or || OR?

我喜歡使用我使用的常用構建命令的短名稱。 我也喜歡他們notify-send當他們完成時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函數而不是外部命令,你可以進行一些內省 - 查看BASH_SOURCE數組來檢查代碼調用中涉及的堆棧幀 - 但這非常脆弱,絕不是一個好的做法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM