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.
Shell Step by Step (3) —— Stdin & if的更多相关文章
- 精通initramfs构建step by step
(一)hello world 一.initramfs是什么 在2.6版本的linux内核中,都包含一个压缩过的cpio格式 的打包文件.当内核启动时,会从这个打包文件中导出文件到内核的rootfs ...
- Step By Step(Lua输入输出库)
Step By Step(Lua输入输出库) I/O库为文件操作提供了两种不同的模型,简单模型和完整模型.简单模型假设一个当前输入文件和一个当前输出文件,他的I/O操作均作用于这些文件.完整模型则使用 ...
- WPF Step By Step 系列-Prism框架在项目中使用
WPF Step By Step 系列-Prism框架在项目中使用 回顾 上一篇,我们介绍了关于控件模板的用法,本节我们将继续说明WPF更加实用的内容,在大型的项目中如何使用Prism框架,并给予Pr ...
- Linux 学习 step by step (2)
Linux 学习 step by step (2) Linux,想要我说爱你真的不容易了,尽管,你是ubutun,尽管,你有蛮界面.但是,操作你,还是没有操作windows那么的如鱼得水了.为了更 ...
- HDU 2815 扩展baby step giant step 算法
题目大意就是求 a^x = b(mod c) 中的x 用一般的baby step giant step 算法会超时 这里参考的是http://hi.baidu.com/aekdycoin/item/2 ...
- Step by Step Process of Migrating non-CDBs and PDBs Using ASM for File Storage (Doc ID 1576755.1)
Step by Step Process of Migrating non-CDBs and PDBs Using ASM for File Storage (Doc ID 1576755.1) AP ...
- POJ 2417 Discrete Logging ( Baby step giant step )
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3696 Accepted: 1727 ...
- Step by step Dynamics CRM 2011升级到Dynamics CRM 2013
原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...
- Step by Step 创建一个新的Dynamics CRM Organization
原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...
随机推荐
- [D3] Start Visualizing Data Driven Documents with D3 v4
It’s time to live up to D3’s true name and potential by integrating some real data into your visuali ...
- easyui datagrid editor checkbox 单击事件
Easyui datagrid treegrid中能够为行追加checkbox元素.比如: $('#tt').treegrid({ url:'get_data.php', idField:'id', ...
- WPF学习笔记——概述
如果你选择WPF,多半原因是因为折服于它那震撼性的用户体验.纵观WPF整个知识体系,其内容并不复杂,但却比较细碎,不易理清.以下内容是对WPF部分内容的简单概括,希望读者能够对WPF框架有个大体认识. ...
- [Node] Catch error for async await
When we try to do MongoDB opration, mongoose return Promise, we can use async/await to simply the co ...
- Ehcache与Memcache的差别
ehcache是纯java编写的.通信是通过RMI方式,适用于基于java技术的项目. memcachedserver端是c编写的.client有多个语言的实现,如c.php(淘宝.sina等各大门户 ...
- js课程 3-10 js中字符串函数数组函数和其它语言中对应函数的区别和联系是什么
js课程 3-10 js中字符串函数数组函数和其它语言中对应函数的区别和联系是什么 一.总结 一句话总结:js中是对象点方法的形式,这些方法都是对象的方法,而在php.java中却不是这样. 1.j ...
- Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- eclipse jdt
http://www.cnblogs.com/hoojo/p/use_eclipse_ant_javac_JDT_compiler_class.html
- C++ 工具类 —— 词条类(Entry)
Entry 以键值对(key-value pair)的形式定义. template <typename K, typename V> struct Entry{ K key; V valu ...
- css实现图片未加载完成时占位显示
通过css控制,可以实现加载网络图片时,未加载完成的时候显示本地一张占位图,加载完成后显示网络图片: 原理:通过在img标签的after伪元素上添加一张占位图,并且img都设置为position:re ...