1.shell基础read,expr,text

shell基础:

在这里插入图片描述
今天瞅瞅学了啥啊 :… … #好吧昨天学的,学了一点,希望还记着点

read命令

从键盘缓存区读入数据,然后赋值给变量

例子:vim read.sh

#!/bin/bash
read a b c

echo "the first is $a"
echo "the second is $b"
echo "tne thread is $C"

执行: ABC  123  /bin/bash
结果:the first is ABC
	 the second is 123
	 tne thread is /bin/bash

expr命令

表示要算数运算,对整数进行算术运算

expr 3 + 5  #8,注意运算符前后有空格
expr 3 / 2  #1,为整除意思
expr 4 \* 7 #28,\为转义字符,吧*特殊意思转为
			普通的乘号
expr `expr 4 + 6` \* $var1   #  ``相当于小括号
			但要区别于B=$(ls -l)

test变量测试

test str1 == str2#是否相等
test str1 != str2 #是否不相等
test str1,test -z str1 # 测试是否为空
test -n str1 #测试是否不为空
测试整数
test int1 -eq int2 等于
test int1 -ge int2 大于等于
test int1 -gt int2 大于
test int1 -le int2小于等于
test int1 -lt int2小于
test int1 -ne int2 不等于
可以省略test:[int 1-eq int2]
测试文件
test -d file 是否为目录 ,-f文件,-x可执行,-r可读,
-w可写,-e存在,-s是否为空
可写成:[ -x file]

#####此文纯属小白笔记,有不对之处大佬使劲喷,杠精请绕过,#####
在这里插入图片描述

原创文章 35 获赞 58 访问量 5914

猜你喜欢

转载自blog.csdn.net/weixin_43221560/article/details/89838369