[ “
a
"
=
"
a"="
a"="b” ] #等于
[ “
a
"
!
=
"
a"!="
a"!="b” ] #不等
[ “
a
"
−
e
q
"
a" -eq "
a"−eq"b” ] #等于
[ “
a
"
−
n
e
"
a" -ne "
a"−ne"b” ] #不等于
[ “
a
"
−
l
e
"
a" -le "
a"−le"b” ] #小于或等于
[ “
a
"
−
g
e
"
a" -ge "
a"−ge"b” ] #大于或等于
[ “
a
"
−
g
t
"
a" -gt "
a"−gt"b” ] #大于
[ “
a
"
−
l
t
"
a" -lt "
a"−lt"b” ] #小于
[ “
a
"
−
n
e
"
a" -ne "
a"−ne"b” -a “
a
"
−
g
t
"
a" -gt "
a"−gt"b” ] #-a必须条件都满足
[ “
a
"
−
n
e
"
a" -ne "
a"−ne"b” -o “
a
"
−
g
t
"
a" -gt "
a"−gt"b” ] #-a条件至少满足一个
[ -z “$a” ] #是否为空
[ -e “file” ] #是否存在
[ -f “file” ] #普通文件
[ -b “file” ] #块设备
[ -S “file” ] #套接字
[ -c “file” ] #字符设被
[ -L “file” ] #软链接
判断文件内容是否一样
#!/bin/bash
[ "$1" == "/etc/passwd" ] && echo YES || echo NO
判断输入的数字是否在1到10范围内
判断文件类型
#!/bin/bash
[ -z "$1" ] && {
echo "无输入"
exit 1
}
[ -e "$1" ] || {
echo "不存在"
exit 1
}
[ -f "$1" ] && {
echo "普通文件"
exit 0
}
[ -b "$1" ] && {
echo "块设备"
exit 0
}
[ -S "$1" ] && {
echo "套接字"
exit 0
}
[ -c "$1" ] && {
echo "字符设备“
exit 0
}
[ -L "$1" ] && {
echo "软链接"
exit 0
}