As explained in the manual, all scripts run with sh -e
. That means any unhandled command failure will terminate the script with an error. If you have code which might return failure, you would code it like
command || true
or wrap it in a conditional or something.
By the by, your code is better written as
ps ax | grep "[p]ostgres: wal writer process"
See also https://stackoverflow.com/questions/9375711/more-elegant-ps-aux-grep-v-grep
So in summary, you would probably be looking for something like
if ps aux | grep '[p]ostgres: wal writer process' then : already running else : start it up fi
Now that grep
is run as part of a conditional, a failure is no longer considered unhandled (even if you don't have an else
clause!) and so it will run safely under set -e
.