判斷參數的個數
-ne 不等於
-eq 等於
-gt 大於
-lt 小於
-ge 大於等於
-le 小於等於
if [ "$#" -ne 1 ];then
echo "no equal"
fi
判斷文件存在
-f 文件存在
! -f 文件不存在
if [ -f "file.txt" ];then
echo "file exist"
fi
if [ ! -f "file.txt" ];then
echo "file no exist"
fi
判斷目錄存在
-d 目錄存在
! -d 目錄不存在
if [ -d "fold" ];then
echo "fold exist"
fi
if [ ! -d "fold" ];then
echo "fold no exist"
fi
判斷字符串相等
== 字符串相等
!= 字符串不相等
if [ "$1" == "-h" ];then
echo "show help"
fi
判斷字符串長度是否為0
-z 字符串長度為0
-n 字符串長度不為0
if [ -z "" ];then
echo "string length 0"
fi
if [ -n "nonull" ];then
echo "string length no 0"
fi
