2013-05-06 76 views

回答

95

因此,要使您的表达工作,更改&&-a将做的伎俩。

这是正确的这样的:

if [ -f $VAR1 ] && [ -f $VAR2 ] && [ -f $VAR3 ] 
then .... 

或类似

if [[ -f $VAR1 && -f $VAR2 && -f $VAR3 ]] 
then .... 

甚至

if [ -f $VAR1 -a -f $VAR2 -a -f $VAR3 ] 
then .... 

你可以找到给有想在这个问题bash : Multiple Unary operators in if statement进一步的细节和一些参考What is the difference between test, [ and [[ ?

+1

非常感谢!我会很快接受答案! ;) – 2013-05-06 09:57:19

+8

请注意,[POSIX](http://pubs.opengroup.org/onlinepubs/000095399/utilities/test.html#tag_04_140_16)建议使用'&&'和'||' -a'和'-o',所以如果你正在编写可移植的代码,那么首先使用符号,否则就跳过第三步,特别是因为如果你需要对表达式进行分组,它会变得难以理解。 – 2013-05-06 12:22:41