Linux Shell脚本编程while语句
do
uptime
sleep 3
done
ghostwu@dev:~/linux/shell/flow_control$ sh while.sh &
[1] 12867
do
uptime >> log.txt
sleep 3
done
06:14:32 up 33 min, 1 user, load average: 0.33, 0.35, 0.32
06:14:35 up 33 min, 1 user, load average: 0.33, 0.35, 0.32
06:14:38 up 33 min, 1 user, load average: 0.31, 0.34, 0
...
3,进程调度相关命令
fg: 把当前脚本或者任务放到前台执行。如果指定某个任务:fg 任务编号。 任务编号通过jobs查询
bg: 把任务放到后台执行
jobs:查看当前执行的脚本或者任务
ctrl+z:暂停执行当前的脚本
sh while1.sh & : 加上&,表示后台执行脚本
sh while.sh
^Z
[1]+ Stopped sh while.sh
ghostwu@dev:~/linux/shell/flow_control$ jobs
[1]+ Stopped sh while.sh
ghostwu@dev:~/linux/shell/flow_control$ bg
[1]+ sh while.sh &
ghostwu@dev:~/linux/shell/flow_control$ jobs
[1]+ Running sh while.sh &
ghostwu@dev:~/linux/shell/flow_control$ sh while.sh &
[2] 13411
ghostwu@dev:~/linux/shell/flow_control$ jobs
[1]- Running sh while.sh &
[2]+ Running sh while.sh &
ghostwu@dev:~/linux/shell/flow_control$ fg
sh while.sh
^Z
[2]+ Stopped sh while.sh
ghostwu@dev:~/linux/shell/flow_control$ bg
[2]+ sh while.sh &
ghostwu@dev:~/linux/shell/flow_control$ jobs
[1]- Running sh while.sh &
[2]+ Running sh while.sh &
i=0
while [ $i -lt 5 ]
do
echo $i
(( i++ ))
done
i=0
while [[ $i -lt 5 ]]
do
echo $i
(( i++ ))
done
i=0
while (( i < 5 ))
do
echo $i
(( i++ ))
done
1+2+3..+100=5050
ghostwu@dev:~/linux/shell/flow_control$ cat sum.sh
#!/bin/bash
while (( i <= 100 ))
do
(( sum = sum + i ))
(( i++ ))
done
echo "1+2+3..+100="${sum}
read -p "请输入一个数吧:" n
expr $n + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo "请输入一个数字"
type_num
fi
}
(( count++ ))
if [ $n -eq $sum ]; then
echo "你猜中了,你的次数是:"${count}
if [ $count -lt 3 ]; then
echo "你太厉害了"
elif [ $count -ge 3 -a $count -lt 6 ]; then
echo "还是不错的,加油"
else
echo "你有点水啊"
fi
exit 0
elif [ $n -gt $sum ]; then
echo "猜大了"
type_num
else
echo "猜小了"
type_num
fi
}
type_num
while true
do
guess
done
}
Linux Shell脚本编程while语句的更多相关文章
- Linux Shell脚本编程while语句案例
1,每隔3秒,打印一次系统负载 #!/bin/bash while true do uptime done 2,把监控结果保存到文件,在后台执行,然后用tail -f监控文件变化 ghostwu@de ...
- Linux shell脚本编程if语句的使用方法(条件判断)
if 语句格式if 条件then Commandelse Commandfi 别忘了这个结尾If语句忘了结尾fitest.sh: line 14: syntax error: unex ...
- Linux shell脚本编程(三)
Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...
- Linux shell脚本编程(二)
Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...
- Linux shell脚本编程(一)
Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...
- Linux Shell脚本编程--Linux特殊符号大全
Linux Shell脚本编程--Linux特殊符号大全 linux_shell 特殊符号的介绍 2011
- Linux Shell脚本编程-基础1
概述: shell脚本在Linux系统管理员的运维工作中非常重要.shell脚本能够帮助我们很方便的管理服务器,因为我们可以指定一个任务计划,定时的去执行某一个脚本以满足我们的需求.本篇将从编程基础 ...
- 【学习】Linux Shell脚本编程
1.脚本的组成和执行 Linux shell脚本的结构并不复杂,其主要由变量.内部命令以及shell的语法结构和一些函数.其他命令行的程序等组成,以下是一个简单的shell脚本. #!/bin/bas ...
- Linux shell脚本编程基础之练习篇
shell脚本编程基础之练习篇. 1.编写一个脚本使我们在写一个脚本时自动生成”#!/bin/bash”这一行和注释信息. #!/bin/bash ] then echo "请输入一个参数& ...
随机推荐
- Git的一些概念(二)
一.Git的结构 二.Git和代码托管中心 代码托管中心的任务:维护远程库 1. 局域网内 GitLab 服务器 -- 可以自己搭建 2. 外部环境 GitHub 码云 三.本地库和远程库 1. 团队 ...
- hadoop 源码编译
hadoop 源码编译 1.准备jar 1) hadoop-2.7.2-src.tar.gz 2) jdk-8u144-linux-x64.tar.gz 3) apach-ant-1.9.9-bin. ...
- 【oracle】表说明 COMMENT ON的用法
- B1038 统计同成绩学生 (20 分)
#include<iostream> #include<cstring> using namespace std; const int maxn = 10010; int sc ...
- 7.27 NOIP模拟测试9 随 (rand)+单(single)+题(problem)
T1 随 (rand) dp+矩阵优化+原根 看着题解懵了一晚上加一上午,最后还是看了DeepinC的博客才把暴力码出来,正解看得一知半解,循环矩阵也不太明白,先留坑吧.暴力里用二维矩阵快速幂会tle ...
- JAVA基础系列:内部类获取外部类的成员变量
内部类获取外部类的成员变量,使用 外部类类名.this.变量名 的形式获取 public class Outer { public String name = "outer"; c ...
- JVM学习笔记1
1.运行时数据结构 2.堆分代 3.垃圾收集器 Parallel Scavenge收集器:新生代称为PSYoungGen,老年代称为ParOldGen,永久代称为Metaspace ParNew收集器 ...
- iphone 移动端操作记录
iPhone和Safari浏览器的后退按钮操作,是直接载入缓存中的页面,不会加载js文件,不会执行ready,onload函数,但是加载html页面会跑pageshow事件,因此有回退动作需要重新加载 ...
- 基于canvas自动化运维工具
首先我们的工具绝对顶尖,绝对绚丽.如果有需要代码,可以加我微信索取.18500591275 前几天有个客户找到我,问我这个能不能做,我看自己也干了10年前端了,实在做不了,后来人家说给你10000你能 ...
- Larave框架下Contracts契约的解析
本篇文章给大家带来的内容是关于Larave框架下Contracts契约的解析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. Contracts Laravel 的契约是一组定义框架提 ...