bash的数值代表和其它代表相反:0表示true;非0代表false。
#!/bin/sh
PIDFILE="pid"# true=nginx进程运行 false=nginx进程未运行
checkRunning(){# -f true表示普通文件if [ -f "$PIDFILE" ]; then# -z 字符串长度为0trueif [ -z "`cat $PIDFILE`" ];thenecho "ERROR: Pidfile '$PIDFILE' exists but contains no pid"return "1";fiPID="`cat ${PIDFILE}`"RET="`ps -p "${PID}"|grep nginx`"# -n 字符串长度不为0为trueif [ -n "$RET" ];thenecho "${RET}"return "0";fifireturn "1";
}checkT_F(){return 2
}status(){if (checkRunning);thenPID="`cat $PIDFILE`"echo "'$SERVICE_NAME' is running (pid '$PID')"exit 0fiecho "'$SERVICE_NAME' not running"exit 1
}case "$1" instatus)status;;zz)if [ -z "123" ];thenecho "123 lenhth is 0"elseecho "123 length is not 0"fi;;check)if checkT_F ;thenecho '2 is true'else echo '2 is flase'fi;; *)
esac