手机
当前位置:查字典教程网 >脚本专栏 >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脚本编程之循环语句学习笔记】相关文章:

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

shell脚本中28个特殊字符的作用简明总结

5个Shell脚本编程入门练习例子

Shell中的循环语句for、while、until实例讲解

shell脚本学习与总结

Linux Shell脚本编程的注意事项

Shell脚本获取进程的运行时间

shell脚本编程之case语句学习笔记

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

Linux shell脚本编程if语句的使用方法(条件判断)

精品推荐
分类导航