I have a very simple bash script that curls a URL, counts a substring in the response, and runs some code if it finds the string.
Originally, I wrote it like this:
RESP=$(curl -s 'https://theurl.com' | grep -ic substring)
if [ $RESP > 0 ];
do something
else
do something else
fi
This worked great from my terminal prompt.
When I set it up to run in launchd as a local user launch agent, the if statement never evaluated to true.
Things I tried during debugging:
- Ensuring both were using /bin/bash (they were) and running as me.
- Sending the variable to stdout to confirm.
- Running them without the curl, just grepping a local file.
Eventually, I was able to get it to work by changing the if to:
if [ $RESP -ge 1 ]
That works in both places, but I can't figure out why the exact same script in the exact same interpreter would evaluate differently in both places.
Any ideas?