《shell条件测试语句,字符串测试apache是否开启》
时间:2014-06-02 11:47:20
收藏:0
阅读:180
还得我想了10分钟才明白”!=“和"-n"的用法区别,做个笔记捋一捋
第一种方法:测试apache是否开启?字符串测试
#!/bin/bash
web=`/usr/bin/pgrep httpd`
if [ -n "$web" ]; //$web返回值是否为空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi
第二种:
#!/bin/bash
web=`/usr/bin/pgrep httpd`
if [ "$web" !=“” ]; //$web返回值是否等于空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi
评论(0)