bash 错误:Shell 脚本返回一元运算符是预期的错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10428028/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:11:07  来源:igfitidea点击:

Error : Shell script returns unary operator is expected error message

bashshellscripting

提问by KItis

i am fixing a given shell script and i am getting following error message

我正在修复给定的 shell 脚本,但收到以下错误消息

line 322: [: ==: unary operator expected

this error is returned from this line.

这个错误是从这一行返回的。

 if [  == "managed?.out" ];then

could someone explain me what makes this error

有人可以解释一下是什么导致了这个错误

Also could someone explain what is the purpose of using ? in the"managed?.out"

也有人可以解释使用的目的是什么?在“托管?.out”中

thanks in advance for any help

提前感谢您的帮助

回答by codaddict

You need to quote $4:

您需要引用$4

if [ "" == "managed?.out" ];then

回答by Raphael Roth

change the if statement to

将 if 语句更改为

if [ "" == "managed?.out" ];then

The double-quotes are only necessary as you use $4, if your variable would be $string, you would not need them.

只有在使用 $4 时才需要双引号,如果变量是 $string,则不需要它们。

should "?" be interpreted as a bash-wildcard? if yes, you need to use

应该 ”?” 被解释为 bash 通配符?如果是,您需要使用

if [[ "" == managed?.out ]];then

回答by chemila

try:

尝试:

if [[  == "managed?.out" ]];then