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 ...
随机推荐
- codeforces Round 246 D. Prefixes and Suffixes (后缀数组 || KMP)
题目大意: 求一个子串,子串既是前缀又是后缀. 然后再求出它在整个串中出现的次数. 思路分析: 能够非常easy想到怎样推断一个串既是前缀又是后缀. 仅仅须要它与 sa[0] 的lcp 等于 整个串的 ...
- thinkphp模拟请求和参数绑定
thinkphp模拟请求和参数绑定 一.总结 1.网页传过来的参数是可以修改的:get或者post等方式 传过来的参数是可以修改的 dump($request->get(['id'=>2 ...
- eclipse启动tomcat报错
错误信息: 严重: A child container failed during start java.util.concurrent.ExecutionException: org.apach ...
- [RxJS] Subject: an Observable and Observer hybrid
This lesson teaches you how a Subject is simply a hybrid of Observable and Observer which can act as ...
- Win或Linux中编译安装软件的命令解析: configure; make; make install
原文地址:http://www.cnblogs.com/Jerry-Chou/archive/2010/12/18/1909843.html 翻译一篇文章,我最早从这篇文章中了解到为什么Linux平台 ...
- 如何搭建自己CDN服务器
转载:http://server.zzidc.com/fwqpz/587.html 目前在免费CDN市场上,360因为“免费”而越做越大,加速乐做的很早.但因免费的节点不多,好多用户都被强走了.安全宝 ...
- js如何将字符串作为函数名调用函数
js将如何字符串作为函数名调用函数 一.总结 一句话总结:用eval来实现.eval可以执行参数字符串. 二.js将字符串作为函数名调用函数 比如我现在有一个字符串str = "func_a ...
- js进阶ajax函数封装(匿名函数作为参数传递)(封装函数引入文件的方式非常好用)
js进阶ajax函数封装(匿名函数作为参数传递)(封装函数引入文件的方式非常好用) 一.总结 2.匿名函数作为参数传递 二.js进阶ajax函数封装 ajax1.js function ajax(ur ...
- [Ramda] allPass, propEq
const needs = ['wifi', 'shower', 'laundry']; const homes = [{ name: 'Home 1', wifi: 'y', shower: 'y' ...
- Java Queue的使用
Queue的成员函数 add 增加一个元索 如果队列已满,则抛出一个IIIegaISlabEepeplian异常 rem ...