我知道可以使用-z
测试字符串是否为空,使用-n
测试字符串是否非空。因此,我在Ubuntu 10.10中编写了一个脚本:
#!/bin/bash
A=
test -z $A && echo "A is empty"
test -n $A && echo "A is non empty"
test $A && echo "A is non empty"
str=""
test -z $str && echo "str is empty"
test -n $str && echo "str is non empty"
test $str && echo "str is non empty"
令我惊讶的是,它输出了:
A is empty
A is non empty
str is empty
str is non empty
我认为应该是这样的
与IT技术有关的内容
A is empty
str is empty
有没有Linux专家能解释一下为什么?
谢谢。