美文网首页
linux bash流程控制while

linux bash流程控制while

作者: Dylan_abaa | 来源:发表于2020-06-22 09:41 被阅读0次

while condition

do 

    command

done

#!/bin/bash

int=1

while(( $int<=5 ))

do 

 echo $int

 let "int++"

done

挨个输出12345

使用了 Bash let 命令,它用于执行一个或多个表达式,变量计算中不需要加上 $ 来表示变量

while循环可用于读取键盘信息。下面的例子中,输入信息被设置为变量MAN,按结束循环。

echo 'press <CTRL-D> exit'

echo -n 'Who do you think is the most handsome: '

while read MAN

do 

     echo "Yes!$MANis really handsome"

done

无限循环:

while :

do 

 command

done

或者

while true

do 

 command

done

或者

for (( ; ; ))

相关文章

网友评论

      本文标题:linux bash流程控制while

      本文链接:https://www.haomeiwen.com/subject/vbcnxktx.html