还得我想了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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-12-22
  • 2021-08-18
  • 2021-09-20
猜你喜欢
  • 2021-05-15
  • 2021-08-21
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2021-11-10
相关资源
相似解决方案