Shell Step by Step (3) —— Stdin amp; if

news/2024/6/29 11:38:01

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 ……

热门推荐

  • LNMP环境搭建——Nginx篇

  • 在RHEL6.5中配置本地YUM源

  • Ubuntu下Zabbix安装及使用问题

  • MySQL双主热备问题处理

  • Rsync同步错误处理
  • Fix Elementary Boot Screen (plymouth)
    After Installing Nvidia Drivers
  • LNMP环境搭建——MySQL篇
  • Shell Step by Step (3) —— Stdin & if
  • Shell Step by Step (4) —— Cron & Echo

版权声明:本文博主原创文章,博客,未经同意不得转载|Copyright ©2011-2015, Kallen Ding, All Rights Reserved.


http://www.niftyadmin.cn/n/1974604.html

相关文章

nginx搭建文件服务器

nginx搭建文件服务器 安装&#xff1a; sudo apt-get install nginx 启动&#xff1a; nginx -c /etc/nginx/nginx.conf 或&#xff1a; /etc/init.d/nginx start 创建server文件夹&#xff0c;将server.conf文件放在此文件夹中&#xff1a; sudo mkdir/etc/nginx/server ser…

JavaScropt函数

前言 JavaScript 学习的也有一段时间了,好多东西都没有写出来,所以开始将一些简单的知识点总结一下慢慢的积累沉淀吧! 正文 JavaScript函数声明语法: function functionName(parameters){ 需要执行的代码 }Function()构造函数 函数同样可以通过内置的JavaScript 函数构造器…

Aizu 2450 Do use segment tree 树链剖分+线段树

Do use segment tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.bnuoj.com/v3/problem_show.php?pid39566Description Given a tree with n (1 ≤ n ≤ 200,000) nodes and a list of q (1 ≤ q ≤ 100,000) queries, process the queries in order and …

centos7安装k8s部署系统

centos7安装k8s部署系统 一、环境准备 标题1、设置唯一的静态ip vi /etc/sysconfig/network-scripts/ifcfg-ens33将 BOOTPROTO 改为static BOOTPROTOstatic ONBOOTyes 添加ip、网关和DNS地址&#xff0c;网关可以通过命令&#xff1a;“netstat -rn” 查看 IPADDR192.168.2…

Hibernate 5.0.2加载hibernate.cfg.xml时mapping不生效

2019独角兽企业重金招聘Python工程师标准>>> //Group类 package com.jingtai;public class Group {private int groupId;private String groupName;public void setGroupId(int id){groupId id;}public int getGroupId(){return groupId;}public void setGroupName…

k8s运行minio的yml文件

k8s运行minio的yml文件 apiVersion: apps/v1 kind: Deployment metadata:labels:app: minioname: minionamespace: default spec:replicas: 1selector:matchLabels:app: miniotemplate:metadata:labels:app: miniospec:containers:- args:- server- /data- --console-address-…

端口详解2

5050|多媒体会议控制协议5051|ITA代理5052|ITA管理5137|MyCTS服务器端口5150|Ascend通道管理协议5154|BZFlag游戏服务器5190|America-Online(美国在线)5191|AmericaOnline1(美国在线)5192|AmericaOnline2(美国在线)5193|AmericaOnline3(美国在线)5222|Jabber客户端连接5225|HP(…

虚拟机中Linux系统安装

虚拟机安装完成后就应安装虚拟机了,首先要先有虚拟机的镜像安装文件,可以去搜索下载 打开虚拟机界面创建新的虚拟机 默认典型安装点击下一步 浏览中选择要安装的系统镜像文件,点击下一步安装 定义要安装的虚拟机的作用最为名字,安装位置也是自定义的,我这里装在了专用盘D中…