if-then只能探测命令的退出状态码吗?
是的
但是我们还有test命令
test命令中可以对列出的条件进行判断,如果成立,test命令就会退出并返回退出状态码0。
test condition
和if-then一起使用时:
if test condition
then
commands
fi
注:如果不写test命令的condition部分,它会以非零的退出状态码退出,并执行else语句块。
$ cat test6.sh
#!/bin/bash
#Testing the test command
#
if test
then
echo "No expression returns a True"
else
echo "No expression returns a False"
fi
$
$ ./test6.sh
No expression re