shell条件测试语句实例-测试apache是否开启

终于理解了shell条件测试语句”!=“和"-n"的用法区别,于是有了如下的shell脚本,做为练习。
 
第一种方法:测试apache是否开启?字符串测试

#!/bin/bash
# www.jquerycn.cn
web=`/usr/bin/pgrep httpd`
if [ -n "$web" ];  //$web返回值是否为空
then
  echo "httpd is running"
else
  /etc/init.d/httpd start
fi

第二种方法:

#!/bin/bash
# www.jquerycn.cn
web=`/usr/bin/pgrep httpd`
if [ "$web" !=“” ]; //$web返回值是否等于空
then 
  echo "httpd is running"
else
  /etc/init.d/httpd start
fi
原文地址:https://www.cnblogs.com/clarke/p/5454366.html