I need to test this:

kill -0 $LAST_PID;

So I wrote

if [ kill -0 $LAST_PID ] ; then ...

But this results in an error - unknown operator after - or so.

how do I escape the options within if?

  • 1
    Not sure why it's downvoted but since it is, it's probably a bad question and needs to be deleted. – Ondra Žižka Aug 15 '18 at 23:44

It's not if that you're trying to escape it from, it's test / [. But you aren't testing the executing of kill that way; you're testing strings. You want:

if kill -0 "$LAST_PID"; then ...

that will test kill's return code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.