while循環(huán)語句——重復(fù)測試指定的條件,只要條件成立則反復(fù)執(zhí)行對應(yīng)的命令操作
while語句的結(jié)構(gòu)
while 命令或表達(dá)式
do
命令列表
done
while語句簡單應(yīng)用示例
批量添加20個系統(tǒng)用戶帳號, 用戶名依次為“stu1”、“stu2”、……、“stu20” #!/bin/bash i=1 while [ $i -le 20 ] do useradd stu$i echo "123456" | passwd --stdin stu$i &> /dev/null i=`expr $i + 1` done
批量刪除上述添加的20個系統(tǒng)用戶帳號 #!/bin/bash i=1 while [ $i -le 20 ] do userdel -r stu$i i=`expr $i + 1` done
![]() | ![]() .. 定價:¥45 優(yōu)惠價:¥42 更多書籍 |
![]() | ![]() .. 定價:¥225 優(yōu)惠價:¥213 更多書籍 |