Shell Script While Loop Examples
来源:互联网 发布:知乎 华清远见骗局 编辑:程序博客网 时间:2024/06/12 01:27
Can you provide me a while loop control flow statement shell script syntax and example that allows code to be executed repeatedly based on a given boolean condition?
Each while loop consists of a set of commands and a condition. The general syntax as follows for bash while loop:
while [ condition ]docommand1command2commandNdone
- The condition is evaluated, and if the condition is true, the command1,2…N is executed.
- This repeats until the condition becomes false.
- The condition can be integer ($i < 5), file test ( -e /tmp/lock ) or string ( $ans != "" )
ksh while loop syntax:
while [[ condition ]] ; docommand1command1commandNdone
csh while loop syntax:
while ( condition ) commands end
BASH while Loop Example
#!/bin/bashc=1while [ $c -le 5 ]doecho "Welcone $c times"(( c++ ))done
KSH while loop Example
#!/bin/kshc=1while [[ $c -le 5 ]]; doecho "Welcome $c times"(( c++ ))done
CSH while loop Example
#!/bin/cshc=1while ( $c <= 5 )echo "Welcome $c times"@ c = $c + 1end
Another example:
#!/bin/cshset yname="foo"while ( $yname != "" )echo -n "Enter your name : "set yname = $<if ( $yname != "" ) thenecho "Hi, $yname"endifend
Featured Articles:
- Shell Script While Loop Examples
- for&while loop/shell
- linux shell ----while Loop
- shell while loop
- Shell Script Examples: case, count, for, if, while and User input
- shell script - usuage of the for loop
- Keeping You in the Loop – Bash For, While, Until Loop Examples
- 12 Bash For Loop Examples for Your Linux Shell Scripting
- 12 Bash For Loop Examples for Your Linux Shell Scripting
- while loop
- Sample Shell Script To Loop Through All Files
- Bash For Loop Examples
- Bash For Loop Examples
- Loop Invariant Proof examples
- The sample Loadrunner script below shows examples of FOR, DO and DO WHILE LOOPs.
- Oracle FNDLOAD Script Examples
- Unix script 17 - examples
- Shell script - while read line后面的行读不出来
- error LNK2019 unresolved external symbol __imp__*** 的原因之一
- poj 2808题校门外的树(java)
- poj1388——Ugly Numbers
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--低级建模 仿顺序操作(十二)
- linux gb2312 to utf-8
- Shell Script While Loop Examples
- 网友精选25个Java试题
- 目的意义
- .net简谈分层架构思想(彻底分离每个层)——后补
- Linux 注销其他用户
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--12864(ST7565P)液晶驱动(十三)
- 关系数据库的设计范式
- C# 操作Excel ---复制Excel的sheet
- ajax刷新问题更正