Shell入门之嵌套if条件
形式:if...then...[elif...then]...else...fi语法格式:if command | conditionthencommandselif command | condtioncommandsthencommandselsecommandsfi代码示例:#!/bin/bash# grep -v 过滤掉包含grep子进程if ps -ef | grep nginx | g
·
形式:if...then...[elif...then]...else...fi
语法格式:
if command | condition
then
commands
elif command | condtion
commands
then
commands
else
commands
fi
代码示例:
#!/bin/bash
# grep -v 过滤掉包含grep子进程
if ps -ef | grep nginx | grep -v grep &> /tmp/null
then
echo "Nginx is Running"
elif ps -ef | grep httpd | grep -v grep &> /tmp/null
then
echo "Apache httpd is Running"
else
echo "Nginx and Httpd is all Stopped"
fi
# 运行结果
~ % sh 04.if_then_else.sh
Nginx and Httpd is all Stopped
更多推荐
已为社区贡献12条内容
所有评论(0)