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 ...
随机推荐
- 辛星解读之php中的重点函数第一节之数组函数
这里我已经写好它的pdf版本号了,比本博客更加适合阅读.首先说一下它在百度网盘的下载地址把:百度网盘下载 ,假设左边连接跪了.能够在浏览器中输入:http://pan.baidu.com/s/1qW5 ...
- html中radio、checkbox选中状态研究(静下心来看,静下心来总结)
html中radio.checkbox选中状态研究(静下心来看,静下心来总结) 一.总结 1.单选框的如果有多个checked 会以最后一个为准 2.js动态添加checked属性:不行:通过 $(& ...
- linux 查看 *.a *.so 符号表(zt)
objdump -tT libName.so | grep symbel symbolName nm -D libName.so | grep symbel symbolName 很多非常熟悉wind ...
- phpstorm 2018本地激活
这是简书上找到的,害怕以后找不到,记录一下网址为https://www.jianshu.com/p/133af2e4fe3f
- 【26.34%】【codeforces 722A】Broken Clock
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 2、Cocos2dx 3.0游戏开发找小三之引擎简单介绍
尊重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27094663 引擎简单介绍 Cocos2d-x 的 ...
- position:relative和position:absolute的差别及使用方法
这几天在做项目时遇到做选项卡的功能时,标题和内容区域的背景颜色不同.且须要选到当前标题时,此标题以下会出现下边框及小三角边框,这样就会超出标题背景颜色需覆盖以下内容区域.这时就须要用到potition ...
- Java算法--串的简单处理
题目例如以下: 串的处理 在实际的开发工作中.对字符串的处理是最常见的编程任务. 本题目即是要求程序对用户输入的串进行处理.详细规则例如以下: 1. 把每个单词的首字母变为大写. 2. 把数字与字母之 ...
- [Jenkins] Define a pipeline
node{ stage 'checkout' git '[github_url]' def project_path="[project_path]" // everythin i ...
- 使用JSONP解决跨域问题-代码示例
前段时间用JSONP解决了跨域问题,现在不用了,把代码思路记下来,今后说不定还用得上. JS代码 //查询公告数据 function recentpost(){ $.getJSON(cmsUrl+&q ...