if case for while
#!/bin/bash
a=$1
if [ $a ] #判断$1是否为空
then #非空
echo "the input is No:$a"
exit 0
else #空
read -p "input a Nov:" a
#a=$b
fi
case $a in
"1")
echo "your input is No:1"
;;
"2")
echo "your input is No:2"
;;
*)
echo "dont know"
;;
esac
~~~~~~~~~~~~~~~~
#!/bin/bash
ip=(
a
b
c
d
) #ip=("aa" "bb" "cc") 也一样
for i in ${ip[*]} ; do #注意不是ip[$*]
echo $i
done
for ((i=0;i<10;i++));do
echo -n $i
done
#!/bin/bash
name=("Tom" "Tomy" "John")
for i in 0 1 2
do
echo $i:${name[$i]} # name[$*] 也是可以的 注意不是name[*]
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~
while true;do #while 死循环
echo “just test”
done
#!/bin/bash
while [ $# -gt 0 ];do #当$#大于0就执行 until与while相反 until [ $# -lt 1 ];do 执行,直到 $#小于1时 停止
echo $*
shift
done
结果
zzx@ubuntu:~$ sh shift.sh 1 2 3 4 5
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
while true ; do ### shell没do while 相当于 do……while 循环
if [];then
echo " test"
break ####break 退出while循环 继续执行剩下的脚本 如果是exit就退出整个shell 不在执行剩下脚本
fi
done
- while expression
- do
- command
- command
- ```
- done
- 1 #!/bin/sh
- 2 int=1
- 3 while(( $int<=5 ))
- 4 do
- 5 echo $int
- 6 let "int++"
- 7 done
- 1 #用脚本演示使用结束标记控制while循环实现猜1~10内的数
- 2 #!/bin/sh
- 4 echo "Please input the num (1~~10): "
- 5 read num
- 6 while [[ $num != 4 ]]
- 7 do
- 8 if [ $num -lt 4 ]
- 9 then
- 10 echo "Too small ,Try again.."
- 11 read num
- 12 elif [ $num -gt 4 ]
- 13 then
- 14 echo "Too big ,Try again.. "
- 15 read num
- 16 else
- 17 exit 0
- 18 fi
- 19 done
- 20 echo "Yes ,you are right !!"
- 1 #!/bin/sh
- 2 echo "Please input the num:"
- 3 read num
- 4 sum=0
- 5 i=1
- 6 signal=0
- 7 while [[ $signal != 1 ]]
- 8 do
- 9 if [ $i -eq $num ]
- 10 then
- 11 let "signal=1"
- 12 let "sum+=i"
- 13 echo "1+2、、、+$num=$sum"
- 14 else
- 15 let "sum=sum+i"
- 16 let "i++"
- 17 fi
- 18 done
- 1 #!/bin/sh
- 3 echo "Please input arguements is $# "
- 4 echo "What you input : "
- 5 while [[ $* != "" ]]
- 6 do
- 7 echo $1
- 8 shift
- 9 done
if case for while的更多相关文章
- C#中,switch case语句中多个值匹配一个代码块的写法
switch (num) { case 1: Response.Write("1"); break; case 2: case 3: Response.Write("2| ...
- Android Studio快捷键switch case 轻松转换为if else
Android Studio快捷键switch case 轻松转换为if else 今天碰到的问题,没有找到资料,后面找到了方法,这个记下来,转载请注明出处:http://www.cnblogs.co ...
- 你真的会玩SQL吗?Case也疯狂
你真的会玩SQL吗?系列目录 你真的会玩SQL吗?之逻辑查询处理阶段 你真的会玩SQL吗?和平大使 内连接.外连接 你真的会玩SQL吗?三范式.数据完整性 你真的会玩SQL吗?查询指定节点及其所有父节 ...
- java中的switch case
switch-case语句格式如下 switch(变量){ case 变量值1: //; break; case 变量值2: //...; break; ... case default: //... ...
- sql case when...then...else...end 选择判断
达到的需求为: 吓数收回日期为空:当接单日期不等于空和当天减接单日期大于3天时,为1,否则为0:当接单日期为空.最大发织交期不等于空和当天减去最大发织交期大于3天时,为1,否则为0:当接单日期和发织交 ...
- C# 中Switch case 返回不止用break
Switch(temp) { case "A": //跳出循环 break; case "B": //返回值 return var; case "C& ...
- SQL --- Case when 的使用方法
1. Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' E ...
- 2.3switch case 语句注意事项。
#include<stdio.h> int main() { void action1(int, int),action2(int, int); char ch; , b=; ch = g ...
- sh4.case语句
case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构.case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case语句格式如下: ...
- 为什么说在使用多条件判断时switch case语句比if语句效率高?
在学习JavaScript中的if控制语句和switch控制语句的时候,提到了使用多条件判断时switch case语句比if语句效率高,但是身为小白的我并没有在代码中看出有什么不同.去度娘找了半个小 ...
随机推荐
- python isinstance()判断数据类型
举例: d = (1,2,3) print(isinstance(d,int)) #False print(isinstance(d,tuple)) #True print(isinstance(d, ...
- Java提升三:函数式接口
1. 定义 函数式接口即是有且仅有一个抽象方法的接口. 注意: (1)函数式接口只对于抽象方法有要求,对于接口中的默认方法,静态方法,私有方法数量并不作特殊要求. (2)既然函数式接口定义了抽象方法, ...
- 037、Java中利用判断语句实现三目运算的功能
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- pig安装配置及实例
一.前提 1. hadoop集群环境配置好(本人hadoop版本:hadoop-2.7.3) 2. windows基础环境准备: jdk环境配置.esclipse环境配置 二.搭建pig环境 1.下载 ...
- 树莓派1 安装使用 ZeroTier
基于P2P网络的Private LAN工具:ZeroTier Linux (DEB and RPM distributions) We've found a way to make the easy ...
- POJ 2823 滑动窗口 单调队列模板
我们从最简单的问题开始: 给定一个长度为N的整数数列a(i),i=0,1,...,N-1和窗长度k. 要求: f(i) = max{a(i-k+1),a(i-k+2),..., a(i)},i = 0 ...
- NO15 第一关课后考试
第一关课后考试: 1.创建目录/data/oldboy,并且在该目录下创建文件oldboy.txt,然后在文件oldboy.txt里写如内容:inet addr:10.0.0.8 Bcast:10.0 ...
- ruby资料
源码样例 链接: https://pan.baidu.com/s/1mh55bFM 密码: 6cjy 初级代码 链接: https://pan.baidu.com/s/1hschnUW 密码: 8n1 ...
- POJ 3735:Training little cats 联想到矩阵相乘
Training little cats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11208 Accepted: ...
- django 实现 内网访问 和 用花生壳进行内网穿透
1.在setting.py中找到 ALLOWED_HOSTS = [] 改为 ALLOWED_HOSTS = ['*',]2.启动服务时使用如下命令行 python .\manage.py runs ...