Shell Step by Step (3) —— Stdin & if
4.输入输出
#! /bin/bash
# Read users input and then get his name
read -p "Please input your first name: " firstName
read -p "Please input your last name: " lastName
echo -e "Your full name is: $firstName $lastName"
read使用方法:
read [-ers] [-a 数组] [-d 分隔符] [-i 缓冲区文字]
[-n 读取字符数] [-N 读取字符数] [-p 提示符]
[-t 超时] [-u 文件描写叙述符] [名称 ...]
5.条件判别式
-e 是否存在
-nt (newer than) file1 是否比 file2 新
-ot (older than) file1 是否比 file2 旧
-ne 表示 不等于
-eq 等于,如:if ["$a" -eq "$b" ]
-ne 不等于,如:if ["$a" -ne "$b" ]
-gt 大于,如:if ["$a" -gt "$b" ]
-ge 大于等于,如:if ["$a" -ge "$b" ]
-lt 小于,如:if ["$a" -lt "$b" ]
-le 小于等于,如:if ["$a" -le "$b" ]
< 小于(须要双括号),如:(("$a" < "$b"))
<= 小于等于(须要双括号),如:(("$a" <= "$b"))
> 大于(须要双括号),如:(("$a" > "$b"))
>= 大于等于(须要双括号),如:(("$a" >= "$b"))
-z (zero) 是否为零
[ -a FILE ] 假设 FILE 存在则为真。
[ -b FILE ] 假设 FILE 存在且是一个块特殊文件则为真。
[ -c FILE ] 假设 FILE 存在且是一个字特殊文件则为真。
[ -d FILE ] 假设 FILE 存在且是一个文件夹则为真。
[ -e FILE ] 假设 FILE 存在则为真。
[ -f FILE ] 假设 FILE 存在且是一个普通文件则为真。
[ -g FILE ] 假设 FILE 存在且已经设置了SGID则为真。
[ -h FILE ] 假设 FILE 存在且是一个符号连接则为真。
[ -k FILE ] 假设 FILE 存在且已经设置了粘制位则为真。
[ -p FILE ] 假设 FILE 存在且是一个名字管道(F假设O)则为真。
[ -r FILE ] 假设 FILE 存在且是可读的则为真。
[ -s FILE ] 假设 FILE 存在且大小不为0则为真。
[ -t FD ] 假设文件描写叙述符 FD 打开且指向一个终端则为真。
[ -u FILE ] 假设 FILE 存在且设置了SUID (set user ID)则为真。
[ -w FILE ] 假设 FILE 假设 FILE 存在且是可写的则为真。
[ -x FILE ] 假设 FILE 存在且是可运行的则为真。
[ -O FILE ] 假设 FILE 存在且属有效用户ID则为真。
[ -G FILE ] 假设 FILE 存在且属有效用户组则为真。
[ -L FILE ] 假设 FILE 存在且是一个符号连接则为真。
[ -N FILE ] 假设 FILE 存在 and has been mod假设ied since it was last read则为真。
[ -S FILE ] 假设 FILE 存在且是一个套接字则为真。
[ FILE1 -nt FILE2 ] 假设 FILE1 has been changed more
recently than FILE2, or 假设 FILE1
exists and FILE2 does not则为真。
[ FILE1 -ot FILE2 ] 假设 FILE1 比 FILE2 要老, 或者 FILE2 存在
且 FILE1 不存在则为真。
[ FILE1 -ef FILE2 ] 假设 FILE1 和 FILE2 指向同样的设备和节点号
则为真。
[ -o OPTIONNAME ] 假设 shell选项 “OPTIONNAME” 开启则为真。
[ -z STRING ] “STRING” 的长度为零则为真。
[ -n STRING ] or [ STRING ] “STRING” 的长度为非零 non-zero则为真。
[ STRING1 == STRING2 ] 假设2个字符串同样。 “=” may be used
instead of “==” for strict POSIX
compliance则为真。
[ STRING1 != STRING2 ] 假设字符串不相等则为真。
[ STRING1 < STRING2 ] 假设 “STRING1” sorts before
“STRING2” lexicographically in the
current locale则为真。
[ STRING1 > STRING2 ] 假设 “STRING1” sorts after “STRING2”
lexicographically in the current
locale则为真。
[ ARG1 OP ARG2 ] “OP” is one of -eq, -ne, -lt, -le,
-gt or -ge. These arithmetic binary
operators return true if “ARG1” is
equal to, not equal to, less than, less
than or equal to, greater than, or
greater than or equal to “ARG2”,
respectively. “ARG1” and “ARG2” are
integers.
e.g:
if [ "$UID" -ne "$ROOT_UID" ] then ……
版权声明:本文博主原创文章,博客,未经同意不得转载|Copyright ©2011-2015, Kallen Ding, All Rights Reserved.
相关文章
- HDU 5304(Eastest Magical Day Seep Group's Summer-环加外向树生成树计数)[Template:Kirchhoff矩阵]
- Why is VMware Not Compatible With Hyper-V & How to Fix It (windowsreport.com)
- dell 服务器服务编码查询方法(Win & linux)
- V3 - 将来时 future tense —— will / shall 2 & Past perfect ——(I had done) Teacher:Lamb
- Linux bash受限的shell(RESTRICTED SHELL)
- vite&vue3中使用批量导入 import.meta.glob import.meta.globEager
- Go语言开发小技巧&易错点100例(四)
- 【前端学习之HTML&CSS进阶篇】-- CSS第一篇 -- @规则与web字体图标
- HDU 1513 && POJ 1159 Palindrome (DP+LCS+滚动数组)
- iOS进阶_Socket(Socket简介&代码演练)
- Swift的 convenience && designated init
- 第7章 DNS & bind从基础到深入
- 查询排序:order by case when理解(根据一个字段的多个值进行排序)、在order By子句中使用case语句的理解、ORDER BY 2 DESC 中 2 的理解
- Python爬虫之续Urllib&&Jsonpath库的使用
- C&C++控制结构实训(国防科大)
- 学习笔记(21):Python网络编程&并发编程-队列的使用
- Shell - type & which
- 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---45
- 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---44
- 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---26
- 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---17
- 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---06
- 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---05
- 《Linux命令行与shell脚本编程大全 第3版》Shell脚本编程基础---44
- 《Linux命令行与shell脚本编程大全 第3版》Shell脚本编程基础---14
- 《Linux命令行与shell脚本编程大全 第3版》Shell脚本编程基础---10
- 《Linux命令行与shell脚本编程大全 第3版》Shell脚本编程基础---07
- 11.0 vue3 shallowRef&shallowReactive
- IDEA&Maven中Pom.xml自动生效