3

If I use a "Run Shell Script" action, and then drag an "If" beneath it... it seems it's only able to interact with "Shell Script Result", which I think is any terminal output.

This means the If block can only switch on whether there's output or not.

Is there a way I can switch on exit status? I'd like to pop up a notification on success, or a warning message on failure.

3
  • Are you trying to capture the output of the shell script as a text to be stored in variable? (Or instead gathering the numerical exit status which the shell assigns to $? ) Commented Sep 12, 2024 at 13:35
  • 3
    The reason for the limitation is that "Shell Script Result" defaults to type "File". If you choose type "Number" instead and add echo $? at the end of your script, you can do a numeric comparison (equal, greater than, etc). $? is a variable set by the shell that stores the exit status of the most recently executed command, as mentioned in bmike's comment. Commented Sep 12, 2024 at 13:46
  • 1
    Have you given any thought to using logical AND and logical OR? The basic syntax would look like this -> print foo && print success || print failure. Commented Sep 12, 2024 at 15:43

1 Answer 1

1

If Run Shell Script finishes with a non-zero exit code, the Shortcut stops running immediately. It pops up an alert

Run Shell Script finished with an error.
Exit code: 1

Maybe that alert is already satisfactory for you.

If it's not, then you'll have to do all of your shell error-handling in the shell anyway.

Instead of running your-command, run

$( your-command ) && echo success || echo failure 

Then use a Match action to check if the shell output ends with the word success:

  1. Match success$ in Shell Script Result
  2. If Matches has any value

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.