来自:Linux迷
链接:https:///bash-linux-test-command.html

linuxmi@linuxmi /home/linuxmi/ ⚡ test 1 -eq 2 && echo "yes" || echo "no"no
linuxmi@linuxmi /home/linuxmi/ ⚡ test 1 -eq 1 && echo "yes" || echo "no"yes

test 1 -eq 2 && echo "yes" || echo "no"
test 1 -ge 2 && echo "yes" || echo "no"
test 1 -gt 2 && echo "yes" || echo "no"

test 1 -le 2 && echo "yes" || echo "no"
test 1 -lt 2 && echo "yes" || echo "no"
test 1 -ne 2 && echo "yes" || echo "no"

test "string1" = "string2" && echo "yes" || echo "no"
test "string1" != "string2" && echo "yes" || echo "no"
test -n "string1" && echo "yes" || echo "no"
test -z "string1" && echo "yes" || echo "no"

⚡ test linuxmi -nt linux && echo "yes"

⚡ test -e /home/linuxmi/linuxmi && echo "yes"

test -O /home/linuxmi/linuxmi && echo "yes"

test 4 -eq 4 -a "moo" = "moo" && echo "it is a cow" || echo "it is not a cow"这里的关键部分是-a标志,它代表and。
test 4 -eq 4 && test "moo" = "moo" && echo "it is a cow" || echo "it is not a cow"test -e linuxmi.txt -o -e linuxmi.py && echo "linuxmi exists" || echo "linuxmi does not exist"test -e linuxmi.txt || test -e linuxmi.py && echo "linuxmi exists" || echo "linuxmi does not exist"
⚡ [ -e linux.py ] && echo "linux.py exists" || echo "file1 does not exist"linux.py exists

[ 4 -eq 4 ] && [ "moo" = "moo" ] && echo "it is a cow" || echo "it is not a cow"
[ -e linuxmi.py ] || [ -e linuxmi.txt ] && echo "linuxmi exists" || echo "linuxmi does not exist"来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/758/viewspace-3125275/ ,如需转载,请注明出处,否则将追究法律责任。