Tobias T–

Get back to Today I learned

Comment I already knew that…

I already knew that you can chain bash (or zsh) commands with the logical AND operator (&&):

./ && terminal-notifier -message "Done"

The problem was, if the script was unsuccessful I would never get a notification. Turns out, there is a Semicolon operator (;) that does exactly that: it executes the second command, no matter the result of the first one:

./ ; terminal-notifier -message "Done"

If the script was successful, I get a notification. If it was not, I get one as well.

One important thing: you should be really careful with this. Imagine something like this: cd my-sub-directory ; rm -Rf *. The change directory might fail, and it will delete the files inside the current directory anyways.

For completeness, there is also the logical OR operator (||). It will execute the second command only if the first one failed:

./ || terminal-notifier -message "Script failed"

P.S.: Thanks to Christian I also learned that they can be combined:

./ && terminal-notifier -message "Done success" || terminal-notifier -message "Done failure"

Also available at