My script myscript.sh checks if mysqld is running:
mypid=`pgrep mysqld`
if ! (( $mypid > 0 )); then
echo "no"
else
echo "yes"
fi
Output (running ./myscript.sh as root):
yes
Now if I change the first line to a process that is not running e.g. mysqld123:
mypid=`pgrep mysqld123`
if ! (( $mypid > 0 )); then
echo "no"
else
echo "yes"
fi
Output:
./myscript.sh: line 3: ((: > 0 : syntax error: operand expected (error token is "> 0 ")
no
Expected output: no (without any errors)
So why does changing the process to something that is not running cause a syntax error, how can I resolve it?
pgrepisn't producing any output.