I have a bash script where I am sleeping and then executing a command in a background process. For example

sleep 30s && ./script.sh &

If I grep ps for "sleep 30s" and kill the process associated with it, will it also prevent ./script.sh from running, or will my script.sh be executed with a separate PID?

1 Answer 1


I just tested this, and the result was that the command after the && was not executed. This is because the && is a bash AND operator; in order for an AND command to succeed, both commands it is joining must succeed. If the first one fails, the entire thing fails, so the shell is smart enough to not bother executing a now-superfluous command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .