手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >shell脚本编程之循环语句学习笔记
shell脚本编程之循环语句学习笔记
摘要:本篇博客很简单,看一下shell编程使用到的循环语句,包括for循环,while循环,until循环,for后边跟一个变量,然后是一个集合,...

本篇博客很简单,看一下shell编程使用到的循环语句,包括for循环,while循环,until循环,for后边跟一个变量,然后是一个集合,将集合中的东西赋给这个变量,每次循环执行,这跟java中的foreach很像,while循环和if使用同样的条件判断,满足条件执行语句,until和while相反,不满足条件执行语句,是不是很简单啊,下面看一下代码吧。

复制代码 代码如下:

#!/bin/sh

#for循环最基本的用法

for var in "hello" "xiao ta" "welcome to www.jb51.net"

do

echo -n "$var "

done

echo

#通配符扩展

for var in $(ls *.sh)

do

echo "$var"

done

#while循环,后边和if一样跟的都是条件

echo "please input secret"

read secret

while [ "$secret" != "xiao ta" ]

do

echo "try again"

read secret

done

#until循环和while相反,条件为假才执行

echo "please input text"

read text

until [ "$text" = "xiao ta" ]

do

echo "try again"

read text

done

exit 0

【shell脚本编程之循环语句学习笔记】相关文章:

shell脚本命令行参数简介

linux shell脚本学习xargs命令使用详解

shell脚本编写的俄罗斯方块游戏代码

Shell脚本for循环语句简明教程

linux shell脚本基础知识学习

Bash Shell脚本学习小结

学习shell脚本之前的基础知识[图文]

Shell脚本while、until循环语句简明教程

shell编程基础之认识与学习BASH

分享shell编程中的几个小技巧

精品推荐
分类导航