条件判断式主要有以下6种类型:
[[email protected] test]# ls -l total 8 drwxr-xr-x 2 root root 4096 Jan 17 19:28 shell -rw-r--r-- 1 root root 4 Jan 17 19:29 test.sh [[email protected] test]# [ -d test.sh ] && echo "yes" || echo "no" no [[email protected] test]# [ -f test.sh ] && echo "yes" || echo "no" yes [[email protected] test]# [ -e test.sh ] && echo "yes" || echo "no" yes [[email protected] test]#
[[email protected] test]# a=10 [[email protected] test]# b=20 [[email protected] test]# [ $a -eq $b ] && echo "yes" || echo "no" no [[email protected] test]# [ $a -ne $b ] && echo "yes" || echo "no" yes [[email protected] test]# [ $a -gt $b ] && echo "yes" || echo "no" no [[email protected] test]# [ $a -lt $b ] && echo "yes" || echo "no" yes [[email protected] test]# [ $a -ge $b ] && echo "yes" || echo "no" no [[email protected] test]# [ $a -le $b ] && echo "yes" || echo "no" yes
时间: 2024-11-15 10:19:11