shell for循环
来源:互联网 发布:域名交易 贴吧 编辑:程序博客网 时间:2024/06/07 06:08
shell for循环
for循环一般格式为:
for 变量 in 列表
do
command1
command2
...
commandN
done
列表是一组值(数字、字符串等)组成的序列,每个值通过空格分隔。每循环一次,就将列表中的下一个值赋给变量。
in 列表是可选的,如果不用它,for 循环使用命令行的位置参数。
1、顺序输出当前列表中的数字
for loop in 1 2 3 4 5
do
echo "The value is: $loop"
done
运行结果:
The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5
2、顺序输出字符串中的字符:
for str in 'This is a string'
do
echo $str
done
运行结果:
This is a string
3、显示主目录下以 .bash 开头的文件:
#!/bin/bash
for FILE in $HOME/.bash*
do
echo $FILE
done
运行结果:
/root/.bash_history
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
4、显示/usr目录下所有目录
#!/bin/bash
dir=$(ls -l /usr/ |awk '/^d/ {print $NF}')
for i in $dir
do
echo $i
done
运行结果
bin
etc
games
include
lib
lib64
libexec
local
sbin
share
src
阅读全文
0 0
- shell循环1.for循环
- Shell For 循环
- shell for循环
- shell for循环语句
- shell for 循环
- shell脚本----for循环
- shell中的for循环
- shell中的for循环
- shell for循环
- shell中的for循环
- 十六、Shell for循环
- shell for循环
- shell之for循环
- Shell for循环
- Shell for循环
- shell 之 for 循环
- Shell for循环
- Shell for循环
- 数据结构复习——链栈的一些操作以及表达式中的括号是否配对问题
- yii2 数据库查询
- yii2 笔记(1)
- linux shell获取用户输入
- php脚本#!/usr/bin/env php写法的好处
- shell for循环
- MFC之旅——SelectClipPath()函数的特性
- JSF 退出登录时删除session
- php 自定义函数大全
- linux 自启动tomcat服务
- 特殊字符大全
- css:div垂直居中
- target='_blank' 安全漏洞
- js setInterval每隔一段时间执行一次