使用参数调用函数的 Bash 脚本“if”语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9685836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash script 'if' statement that calls a function with parameters
提问by user265330
I want an if statement in my bash script that does:
我想要在我的 bash 脚本中使用 if 语句:
if [[ "$v" == "A" || my_func $x $y ]] ; then
but I get the error "conditional binary operator expected". I've tried putting quotes round the parameters in the call to my_func, but still no good. Tried playing around with eval, which didn't help either.
但我收到错误“预期的条件二元运算符”。我试过在 my_func 调用中的参数周围加上引号,但仍然不好。尝试玩弄 eval,这也无济于事。
Thanks for any help.
谢谢你的帮助。
回答by kev
You can try:
你可以试试:
if [[ "$v" == "A" ]] || my_func $x $y ; then

