Single branch if statement
If condition; then statement1 statement2fi
Dual-branch if statement
If judgment condition; then statement1 statement2 ...... Else statement3 statement4 ...... Fi
Multi-branch if statement
If condition 1; then statement1 statement2 ...... Elif judgment condition 2; then statement3 statement4 ...... Elif judgment Condition 3; then statement5 statement6 ...... Else statement7 statement8 ...... Fi
Example 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]#
This article is from the "Hezhang" blog, please be sure to keep this source http://hezhang.blog.51cto.com/1347601/1435340