2016-09-21 40 views

回答

2

查看http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_16關於問題的討論-a-o可以提高。一般來說,表達式如何被解析取決於任何參數擴展到的內容。請看下面的測試:

test "$1" -a "$2" 

取決於$1值,這可能是要麼

# Unspecified behavior 
# With three arguments, the first "!", the second argument 
# must be a unary primary like -n or -f. 
test "!" -a "$2" 

test "foo" -a "$2" # Test that "foo" and "$2" are non-zero length strings 

如果$1!test將可以把它看成否定運算符,而不是應檢查其長度的字符串。

另外,test只適用於4個或更少的參數; -a-o通常會導致5個或更多參數傳遞給test