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.

最新文章

  1. 从Bayesian角度浅析Batch Normalization
  2. png图片尺寸大小调整
  3. 初学Node(三)模块系统
  4. Individual Project - Word frequency program-11061171-MaoYu
  5. android打开,保存图片到sd卡,显示图片
  6. linux chmod权限
  7. 解决Xcode升级7.0后,部分.a静态库在iOS9.0的模拟器上,link失败的问题
  8. c#实现输出本月的月历
  9. LINUX 笔记-find 命令常用用法
  10. 20145237 《Java程序设计》第八周学习总结
  11. MySQL系列教程(二)
  12. Linux 使用 top 命令查看系统的运行情况
  13. JavaScript heap out of memory解决方法
  14. Spark FPGrowth (Frequent Pattern Mining)
  15. Set up an SSH key with Sourcetree on macOS
  16. [UE4]Task的定义与使用
  17. git gitignore 如何添加,为何添加了无效
  18. SpringBoot读取配置properties配置文件
  19. java的堆和栈
  20. ASP.NET Core 上传多文件 超简单教程

热门文章

  1. 自定义npm包的创建、发布、更新和撤销
  2. 辛星笔记之高质量JavaScript代码书写要点
  3. Codeforces 467C. George and Job
  4. linux下的打包和压缩
  5. Android中的消息机制:Handler消息传递机制 分类: H1_ANDROID 2013-10-27 22:54 1755人阅读 评论(0) 收藏
  6. 【死磕Java并发】—–J.U.C之AQS(一篇就够了)
  7. ASCII,Unicode和UTF-8终于找到一个能完全搞清楚的文章了
  8. ios开发日期的NSDate,NSCalendar分类
  9. php实现 密码验证合格程序(复杂问题分类,超简单的)(分类+规范编码)
  10. ExtJs中window用法