shell编程基础(3)条件判断语句
来源:互联网 发布:管理数据的重要性 编辑:程序博客网 时间:2024/05/14 01:49
1,带参数的shellscript
#this is program build 5.11 to test shell script############ cxz ####### 5.11 ############echo "you have given $0 $# argument"echo "the argument you give is \n $@"
#$0表示所执行的shellscript $#表示shellscript 所带的参数总数
[ $# -lt 2 ]&&echo "the num of argument is less than 2"&&exit 0
# $# -lt 2表示的是参数总数小于2,注意方括号的空格关系,$#之前和2之后都要有空格
echo "the first argument is $1"echo "the second argument is $2"shift 1
#shift是移位指令,作用是将“第n个参数”往后移动,shift 1则把“第一个参数”个称呼向后移动一个,这个称呼落在了第二个参数上
echo "the fist argument after shift is $1"
上面的程序简单的使用了shellscript 与参数协作,通过shellscript与参数写作,可以通过参数来触发程序中不同的功能
2.条件判断语句
#################This is the program to test if & else ########### cxz ########### 5.11 ###############read -p "please type in the Y/N " ynif [ "$yn" == "y" ] || [ "$yn" == "Y" ];then echo "the answer is yes"
#if语句在Linux中用来判断,和c++中不同,if判断条件后加了;if和[之间必须要有个空格,如果不加这个空格的话,会导致错误”unexpect then, expecting fi”。
#[]中==前后必须加上空格,否则会导致无论怎么判断都执行the answer is yes.
elif [ "$yn" == "n" ] || [ "$yn" == "N" ];then echo "the answer is no"else echo "the answer is unknow"fi
#if 的结尾要带上fi,感觉程序员都是萌萌哒
在使用判断语句的时候,最重要的就是[]有关的空格。一定要注意
0 0
- shell编程基础(3)条件判断语句
- shell编程条件语句
- shell编程-条件判断
- Shell 编程5(条件判断语句if)
- Linux shell脚本编程if语句的使用方法(条件判断)
- Shell编程之流程控制语句(条件判断)
- linux shell条件判断语句
- linux shell条件判断语句
- linux shell条件判断语句
- shell条件判断式语句
- shell 条件判断式语句
- Shell条件判断语句上
- Shell编程笔记--条件判断
- Shell编程之判断条件
- Linux Shell编程-条件判断
- Shell编程笔记--条件判断
- Shell编程笔记--条件判断
- shell编程之条件判断
- 学习有感
- ChickenFly安装
- HTML MIME Type
- response下载文件
- 以我个人一年的求职经历为主要经验来介绍(主要是开发岗位经验)地球人找工作之前期准备
- shell编程基础(3)条件判断语句
- iaas和paas常见技术
- Go语言panic和recover使用
- Android的AlertDialog,setView后去除黑色边框
- BlockingQueue队列详解
- 用代码设置控件的属性
- iOS 在UILabel显示不同的字体和颜色
- HTML的placeholder标签
- burpsuite proxy option running 勾选不了