2012-08-03 54 views
0

我想这谢赫两个选项之一设置:无论是bintrue,或提供str测试两者:布尔值和字符串?

bin=false; str=; if $bin -o [ -n "$str" ]; then echo yes; fi 

echo ES任何东西,因为它应该是,但是:

bin=false; str='str'; if $bin -o [ -n "$str" ]; then echo yes; fi 

不会回应 - 但它应该。我做错了什么?

回答

1

您的-o选项已通过false。您需要||

bin=false; str=; if $bin || [ -n "$str" ]; then echo yes; fi 
bin=false; str='str'; if $bin || [ -n "$str" ]; then echo yes; fi 
+0

@Adobe:之所以说'-o'不工作是,它不是一部分'if'语法(它没有获得通过,以'FALSE',但*有*'假'to'if'),但它是'test'语句的一部分(又名'''')。 – 2012-08-03 09:20:30

+0

@DennisWilliamson:将'$ bin'设置为'echo'。你会看到'-o'正在传递给'$ bin',其结果是'if'。 – choroba 2012-08-03 09:24:00

+0

谢谢你指出。我忽视了“如果”执行其论证的事实。但是,我所说的关于“测试”的部分是正确的。 – 2012-08-03 09:44:24