標籤:if then else
單分支if語句
if 判斷條件;then statement1 statement2fi
雙分支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:
[[email protected] Scripts]# cat ./root.sh#!/bin/bashread -p "Please input an Username in /etc/passwd file: " Local_USERLocal_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[[email protected] Scripts]# ./root.sh Please input an Username in /etc/passwd file: frameThe User frame is common user.[[email protected] Scripts]# ./root.sh Please input an Username in /etc/passwd file: rootThe User root is admin[[email protected] Scripts]#
本文出自 “HeZhang” 部落格,請務必保留此出處http://hezhang.blog.51cto.com/1347601/1435340