11、特殊判断符号
注:[[]]和[]的区别
A、[[]]是[]的扩充。[[]]能够支持*、<、>等特殊符号,不用转义;
B、使用-a、&&、-o、||时,有着不同的限制;
C、[[]]可以进行算术扩展,而[]不行;
D、[[]]能够使用正则表达式,而[]不行;
C、[[]]可以使用通配符*、?、[list]、{list}和模糊匹配符号=~(符号前的参数包含符号后的参数则为真),而[]不行;
使用$1获取脚本文件后缀参数,并进行判断时需要使用[[]],因为$1可能为空。
Eg:
[root@test ~]# if [[ $USER == r* ]]; then echo "hello,$USER"; else echo $USER not; fi
hello,root
[root@test ~]# if [ $USER == r* ]; then echo "hello,$USER"; else echo $USER not; fi
root,not
12、shell中的通配符
Eg:
[root@test ~]# touch file{1,2,3}
[root@test ~]# ls file*
file1 file2 file3
[root@test ~]# ls file[123]
file1 file2 file3
[root@test ~]# ls file[1-3]
file1 file2 file3
[root@test ~]# ls file[1?2]
file1 file2
[root@test ~]# ls file[1?3]
file1 file3
[root@test ~]# ls file[!3]
file1 file2
[root@test ~]#
个人公众号,微信搜索:linux言叙