Score:-3

Mac command line - run command if previous has failed

in flag

On my mac run scripts that take a long time and for this reason I add && say done so that I can hear when the script has finished running while I am doing other things around the house. However, sometimes my code has bugs/typos and so it throws an error. This results in the script interrupting but not saying anything.

Is there something I can add to the command below that will execute even if the command fails?

Current Command

python3 script.py && say done

Suggested command

I would like something like this

python3 script.py && say done otherwise-if-script-failed say failed
Score:4
cn flag

You could use the boolean-OR operator

python3 script.py && say done || say failed

One thing to note about that style: in A && B || C, C will execute if A fails or if B fails. The safer way to write that is

if python3 script.py; then say done; else say failed; fi
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.