标签:if then else
单分支if语句
if 判断条件;then statement1 statement2 fi
双分支if语句
if 判断条件;then statement1 statement2 …… else statement3 statement4 …… fi
多分支if语句
if 判断条件1;then statement1 statement2 …… elif 判断条件2;then statement3 statement4 …… elif 判断条件3;then statement5 statement6 …… else statement7 statement8 …… fi
示例1:
[root@Server3 Scripts]# cat ./root.sh #!/bin/bash read -p "Please input an Username in /etc/passwd file: " Local_USER Local_ID=$(id -u $Local_USER) if [ "$Local_ID" -eq 0 ];then echo "The User $Local_USER is admin" else echo "The User $Local_USER is common user." fi [root@Server3 Scripts]# ./root.sh Please input an Username in /etc/passwd file: frame The User frame is common user. [root@Server3 Scripts]# ./root.sh Please input an Username in /etc/passwd file: root The User root is admin [root@Server3 Scripts]#
本文出自 “HeZhang” 博客,请务必保留此出处http://hezhang.blog.51cto.com/1347601/1435340
shell编程(四)--- 条件判断之if判断,布布扣,bubuko.com
标签:if then else
原文地址:http://hezhang.blog.51cto.com/1347601/1435340