- Published on
Only Run Shell Command If it Exists
- Yair Mark
As part of my day to day flow, I use the excellent noti to create a notification on Mac when a long-running command line job finished. This should also work on Linux and Windows.
noti is pretty straightforward:
longRunningCommand | noti
The above command will run and will call
noti once it is done which triggers a notification.
You can also tell
noti what title to use:
longRunningCommand | noti -t "Super long job complete!"
I regularly use this in build scripts but not all my colleagues do. To get around this we can tell our scripts to only run
noti if it is present. We do this as follows:
if type noti > /dev/null;then noti -t "DONE - Super long script"; fi
then part of the
if statement is only hit if
noti exists otherwise nothing will happen.
This line can easily be slotted into a
makefile target or/and a