一 變量
a=100 #a的變量就是100
echo $a #echo查看a的變量
image.png
取消變量
a=100
unset a #unset 加上變量的a未斑,就是取消a的變量
環(huán)境變量
image.png
二 正則
重要語法
[:alnum] 代表所有的大小寫英文字符和數(shù)字∑蟆0-9《允摇A—Z a-z
[:alpha:] 代表任意英文大小寫字符 A-Z a-z
[:lower:] 代表小寫字符 a-z
[:upper:] 代表大寫字符 A-Z
[:digit:] 代表數(shù)字 ⌒萑堋0-9
grep "[[alnum]]" xxx.txt #使用語法
image.png
三 特殊變量
重要變量方法
@ :代表 "
2" "
4" 之意芽突,每個(gè)變量是獨(dú)立的(用雙引號(hào)括起來)试浙;
1<u>c</u>
3<u>c</u>
1
3 $4"之意。
四 if判斷
image.png
語法
$ touch a.txt
$ test -e a.txt;echo $?
0 # 測(cè)試成功挟秤,命令返回值為 0
$ test -e s.txt;echo $?
1 # 測(cè)試失敗壹哺,命令返回值為 非 0
$ test -f a.txt;echo $?
0
$ test -d a.txt;echo $?
1
文件權(quán)限偵測(cè)
image.png
語法
$ test -r a.txt; echo $?
0
$ test -x a.txt; echo $?
1
$ test -w a.txt; echo $?
0
$ test -u a.txt; echo $? # 判斷 a.txt 文件是否具有 SUID 屬性
1
$ cat a.txt # 查看 a.txt ,此文件內(nèi)容為空
$ test -s a.txt; echo $? # 判斷 a.txt 文件中有內(nèi)容
1 # 命令返回值為 1 ,說明文件中沒有內(nèi)容
$ echo "123" > a.txt
$ test -s a.txt; echo $?
0
比較
image.png
語法
$ touch b.txt
$ ls -l a.txt
-rw-r--r-- 1 shark staff 4 12 17 22:59 a.txt
$ ls -l b.txt
-rw-r--r-- 1 shark staff 0 12 17 23:05 b.txt
$ test a.txt -nt b.txt; echo $? # 判斷 a.txt 是否比 b.txt 新
1 # 返回 1, 表示判斷表達(dá)式不成立
$ test b.txt -nt a.txt; echo $?
0
關(guān)于整數(shù)之間的判定
image.png
語法
$ test 10 -eq 20; echo $? #判斷10是否等于20艘刚,等于的話輸出0管宵,不等于的話則輸出1
1
$ n1=10
$ n2=20
$ test $n1 -eq $n2; echo $?
1
$ test $n1 -lt $n2; echo $? #判斷n1是否小于n2,正確的話輸出0
0
$ test $n1 -ne $n2; echo $? #判斷兩數(shù)值是否不相等攀甚,正確的話輸出0
0
多重判定
image.png