Shell 编程(循环)
for in 循环语句
#!/bin/bash
for x in one two three four
do
echo number $x
done
例:取出passwd中每一行name 并输出 hello + name
#!/bin/bash
LINES=`wc -l /home/eko/passwd | cut -d' ' -f1`
for i in `seq 1 $LINES`
do
echo "hello,`head -n $i /home/eko/passwd | tail -n 1 | cut -d: -f1`"
done
* seq 语句
root@ubuntu:/home/eko# seq 1 5
1
2
3
4
5 root@ubuntu:/home/eko# seq 1 2 10
1
3
5
7
9
for 循环
#!/bin/bash
for((i=1;i<10;i++))
do
echo "hello $i"
done
for file in
#!/bin/bash for file in /proc/*;
do
echo $file is file path \! ;
done #!/bin/bash for file in $(ls *.sh)
do
echo $file is file path \! ;
done
while
while [ $count -le ]; do
echo $count
count=$((count + ))
done
echo "finished"
case
case $变量名 in
模式1)
命令序列1
;;
模式2)
命令序列2
;;
*)
默认执行的命令序列 ;;
esac
Shell 编程(循环)的更多相关文章
- Shell 编程 循环语句
本篇主要写一些shell脚本循环语句的使用. for 循环 指定次数 #!/bin/bash for ((i=1;i<=10;i++)) do echo $i done [root@localh ...
- 1.Shell编程循环语句(if 、while、 until)
循环语句 for循环语句 读取不同的变量值,用来逐个执行同一组命令 格式: for 变量名 in 取值列表 do 命令序列 done 示例:批量创建用户并设置密码 [root@localhost da ...
- Linux Shell编程 循环语法
for循环 for 循环是固定循环,也就是在循环时已经知道需要进行几次循环.有时也把 for 循环称为计数循环.语法: for 变量 in 值1 值2 值3… do 程序 done 在这种语法中,fo ...
- shell编程基础(5)---循环指令
while类型的循环 while类型的循环是不定循环的一种,每一次循环都会验证给出的循环条件,判断是否要进行下一次循环.linux中while循环的写法和c语言中很想,但是条件给出的方式有些区别. 首 ...
- shell编程下 特殊变量、test / [ ]判断、循环、脚本排错
第1章 shell中的特殊变量 1.1 $# $# 表示参数的个数 1.1.1 [示例]脚本内容 [root@znix ~]# cat /server/scripts/show2.sh #!/bin/ ...
- shell编程基础(二): shell脚本语法之分支语句和循环语句
一.分支语句 1.条件测试:test [ 命令test或[可以测试一个条件是否成立,如果测试结果为真,则该命令的Exit Status为0,如果测试结果为假,则命令的Exit Status为1(注意与 ...
- shell编程学习笔记(十):Shell中的for循环
shell编程中可以实现for循环遍历 先来写一个最简单的吧,循环输出从1到10,脚本内容为: #! /bin/sh for i in {1..10} do echo $i done 上面的代码从1到 ...
- 【转】shell编程下 特殊变量、test / [ ]判断、循环、脚本排错
[转]shell编程下 特殊变量.test / [ ]判断.循环.脚本排错 第1章 shell中的特殊变量 1.1 $# $# 表示参数的个数 1.1.1 [示例]脚本内容 [root@znix ~] ...
- shell编程中的 三种结构: 条件if/选择结构case/循环for/while/until等结构 和 函数的用法
shell 函数的使用 (md中, 列表本身是有格式的, 他要产生缩进, 其次,列表项和列表项之间, 可以留有一个空行, 是合法的, 允许的) shell函数,就是 就相当于一个命令来看待和处理的, ...
- shell编程:for 循环
hell 编程——for in 循环 -------for in 格式------- for 无$变量 in 字符串 do $变量 done 一简单的字符串 枚举遍历法,利用for i ...
随机推荐
- STL基础--迭代器和算法
1 迭代器 Iterators 5种迭代器类型 随机访问迭代器: vector, deque, array // 允许的操作 vector<int> itr; itr = itr + 5; ...
- gulp学习总结
一.gulp使用-博客推荐: http://www.sheyilin.com/2016/02/gulp_introduce/ 二.gulp的作用 gulp是一个前端构建工具,它是一个工具框架,可以通过 ...
- Python——pandas读取JSON数据,xml,html数据(python programming)
- jquery插件:select、checkbox、radio的美化
引用文件: <script src=”/InputPick/jqInputFormat.js” type=”text/javascript”></script> <li ...
- vi/vim 光标移动命令(转载)
转载至:https://www.cnblogs.com/Jacklovely/p/6015037.html vi/vim 光标移动命令 移动光标上:k nk:向上移动n行 9999k或gg可以移到第一 ...
- URL传值乱码
JS端: &value=encodeURIComponent("value") C端: HttpUtility.UrlDecode(Request.Params[" ...
- Android--普通注册页面实现(无功能)
reg.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...
- cas client
(The client and server are the same thekeystore) cas client version: 3.5.1(cas-client-core-3.5.1) gi ...
- window系统更新导致很多服务出错
window7,win10,window server各版本系统中,经常会出现下载完成更新补丁后要求重启更新,此时很可能会出现很多服务失效的莫名其妙的问题,比如数据库连不上,IIS某功能不好使等等问题 ...
- Linux netstat命令查看并发连接数
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 解释: 返回结果示例: LAST_ACK 5 (正在等待处理的 ...