if 语句 read -p "Enter your score(0-100): " GRADE if [ $GRADE -ge 85 ] && [ $GRADE -le 100 ] ; then echo "$GRADE is excellent" elif [ $GRADE -ge 70 ] && [ $GRADE -le 84 ] ; then echo "$GRADE is pass" else echo "$GRADE is fail" fi echo "input invalid !!!" for 语句 NUMBER=1 read -p "Enter The Users Password: " PASSWORD #SAVEIFS=$IFS #IFS=$(echo -en "\n") for UNAME in $(cat user.txt) do id $UNAME &> /dev/null if [ $? -eq 0 ] then echo "$UNAME , Already exists" else useradd $UNAME &> /dev/null echo "$PASSWORD" | passwd --stdin $UNAME echo "$UNAME $NUMBER , Creat success" fi done
while 语句 PRICE=$(expr $RANDOM % 1000) TIMES=0 echo $PRICE echo "price range from 0 to 1000,try to guess it!" while true do read -p "please input your anwser: " INF let TIMES++ if [ "$INF" -eq "$PRICE" ]; then echo "congratulations you finished the game !!!,the anwser is $PRICE" echo "you have tried $TIMES times." exit elif [ $INF -gt $PRICE ]; then echo "it is higher" else echo "it is lower " fi done
case 语句
read -p "please input a character and press Enter to confirm: " KEY case "$KEY" in [a-z]|[A-Z]) echo "what you input is alphabet" ;; [0-9]) echo "what you iuput is number" ;; *) echo "what you input is another character" esac