shell两种循环《一》(小白)
来源:互联网 发布:js根据name赋值 编辑:程序博客网 时间:2024/05/29 23:24
while循环
while循环:
while (条件)
do
动作
done
#!/bin/bashwhile :do read -p 'please input your name: ' name read -p 'please input your password: ' pwd if [ $name = 'batman' ] && [ $pwd = '123' ] then echo 'login sucessful' break #continue fidone-----------------用户名密码错误---------------------------please input your name: sbplease input your password: 345please input your name: dashabiplease input your password: 765please input your name: jihlplease input your password: 839828please input your name: -------------用户名密码正确-------------------------------please input your name: batmanplease input your password: 123login sucessful
#!/bin/bashi=1while ((i<10))doecho $i((i++))done-------------------------输出结果----------------------[root@bogon ~]# ./b.sh 123456789
for循环
for (变量) in( 列表)
do
动作
done
#!/bin/bashfor loop in 1 2 3 4 5do echo "The value is: $loop"done-----------------结果----------------------------[root@bogon ~]# ./f.shThe value is: 1The value is: 2The value is: 3The value is: 4The value is: 5--------------例子------------------------------检查内网存活的IP#!/bin/bashfor i in {1..254}do (ping -W 1 -c 1 192.168.1.$i &> /dev/null && echo 192.168.1.$i) & done
shell中的for常用in列表方式:
for i in 1 2 3for i in {1,2,3}for i in {1..9}for i in {9..1}for i in {a..z}for i in {A..Z}for i in {X..Z}for i in $(cmd)for i in $(find ...)
阅读全文
0 0
- shell两种循环《一》(小白)
- Shell 学习笔记 -----运行Shell脚本的两种方法(一)
- for的两种循环的小细节
- SHELL SCRIPT 无聊小程序(一)
- Shell脚本的基本语法(一) if判断、for循环、while循环和until循环
- 一、Shell简介:什么是Shell,Shell命令的两种执行方式
- js两种循环
- 一些列小感悟(一)--点击某个按钮交替触发两种状态的实现
- C#小技巧(一)循环的Remove方法
- 小白(一)
- js中的两种循环
- list的两种循环
- (002)循环队列的两种C/C++实现
- 算法:两种方式(递归/循环)实现二分查找
- 二分查找 (循环、递归两种方法)
- [Shell ]小程序---循环检测文件的一致性
- linux shell学习笔记(一)——光标移动、输出、函数、循环
- shell学习笔记(一):for循环、if语句、通配符、命令代换、引号
- linux 系统配置
- http请求的详细过程
- 小白的docker初学笔记
- PHP 设计模式---原型模式
- 循环结构语句
- shell两种循环《一》(小白)
- Matplotlib 教程
- Log.isLoggable之二源码解析
- VR视频为什么都是弯的?|VR知识
- 表单校验
- 从32位QT开发环境拷贝vs-qt的工程到64位工程中遇到的问题
- 【Spring 核心】(2):AOP的实现
- BZOJ 3585 mex 莫队算法+分块
- Mac系统如何隐藏Dock上的图标