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

I like to have short names for the general build commands that I use. I also like they notify-send me when they are done so that I can multitask while I wait and not watch the terminal.

Now I would like the teams not to notify if I link them. eg.

  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) 

So, can teams find that they are followed by && or || in bash?

+4
source share
1 answer

Not. The general answer is to move the notification outside of your commands:

 b && b2; notify-result $? 

Now, if you implement b and b2 as shell functions rather than external commands, you can do some introspection - looking at the BASH_SOURCE array to check the stack of frames involved in the call code - but this is extremely fragile and by no means good practice.

+4
source

All Articles