Execute Shell Script with no results returns an error

I have an Execute Shell Script action that sets a local variable. If the commands in the script return nothing (an empty string), then the action errors out. For example: this works (the 'ps' command returns text that contains the string "root"):

ps -cA -o user,pid,command | grep "root"

but this version causes an error ("garbage" is not found in the 'ps' result):

ps -cA -o user,pid,command | grep "garbage"

An empty (null) string should be as valid as any other string. If I add an 'echo x' before the 'ps', the action still errors out. Why does a null string result cause an error?

Hey Jeffry,

The shell script isn't posting a null string per se – it's exit status indicates an error condition, since the command failed.

Keyboard Maestro has tools for managing this in the gear menu of the Execute a Shell Script action.

image

Execute Shell Script – Allow Error to Flow Through v1.00.kmmacros (8.0 KB)

You can also control the result from within the shell script itself:

Execute a Shell Script.kmactions (856 B)

-Chris