while

while

死循环语句可以用来观察内存变化 while后面要加:

0.5秒更新一次内存

[root@u test]# cat 7.sh

while :

do

    free

    sleep 0.5

    clear

done 

[root@u test]#

 

 

echo -e能识别\n这样代表回车符的字符表达

[root@u test]# cat 7.sh

#!/bin/bash

 

var1="AAA"

var2="BBB"

var3="CCC"

while :

do

    clear

    echo -e "A:${var1}\nB:${var2}\nC:${var3}"

    temp=$var1

    var1=$var2

    var2=$var3

    var3=$temp

    sleep 1

done

[root@u test]#

 

输出1到10

[root@u test]# cat 8.sh

#!/bin/bash

count=1

while (( $count <= 10 )) 

do

    echo $count

    ((count++))

done

 

[root@u test]#

 

 

如果输入密码正确,就显示================,否则提示错误

[root@u test]# cat 9.sh

while :

do

    read -p 'your name:' name

    read -p 'passwd:' psd

    if [ $name = 'root' -a $psd = '12345678' ]

          then

             echo 'login successful ,welcome da SB'

            # exit

             break 

    else

         echo 'error'

    fi

     

done 

 

echo '=================='

[root@u test]#

 

 

posted @ 2017-12-30 23:00  森森2017  阅读(111)  评论(0编辑  收藏  举报