// 数值测试 $ if test 5 -eq 5;then echo "YES"; else echo "NO"; fi YES $ if test 5 -ne 5;then echo "YES"; else echo "NO"; fi NO // 字符串测试 $ if test -n "not empty";then echo "YES"; else echo "NO"; fi YES $ if test -z "not empty";then echo "YES"; else echo "NO"; fi NO $ if test -z "";then echo "YES"; else echo "NO"; fi YES $ if test -n "";then echo "YES"; else echo "NO"; fi NO // 文件测试 $ if test -f /boot/System.map; then echo "YES"; else echo "NO"; fi YES $ if test -d /boot/System.map; then echo "YES"; else echo "NO"; fi NO // 各种测试的组合 // 如果a,b,c都等于下面对应的值,那么打印YES,这里通过-a进行"与"测试 $ a=5;b=4;c=6; $ if test $a -eq 5 -a $b -eq 4 -a $c -eq 6; then echo "YES"; else echo "NO"; fi YES // 测试某个“东西”是文件或者目录,这里通过-o进行“或”运算 $ if test -f /etc/profile -o -d /etc/profile;then echo "YES"; else echo "NO"; fi YES // 测试非运算 $ if test ! -f /etc/profile; then echo "YES"; else echo "NO"; fi NO
|