|
Executive summary: You already got the answer. ps lists all processes, and grep checks if the selected process is among them.
Every command in a shell script sets its exit status. The exit status of a pipeline is the exit status of the last command in that pipeline. The exit status is available in the variable $? but the idiomatic way to do this is usually with an if statement, like the one aigles already posted.
if executes the commands you give it as parameters, and takes the then branch if the exit status was zero (meaning success) and the else branch otherwise. If the selected branch is missing, it does nothing. (Some shells allow the then branch to be left out, but this is not entirely portable; in all events, the else branch is optional.)
|