bash 意外标记“(”附近的语法错误

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

syntax error near unexpected token `('

bashshell

提问by Radek

I am trying to execute

我正在尝试执行

sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application (1995)

but I get this error bash: syntax error near unexpected token('`

但我收到此错误 bash: syntax error near unexpected token('`

sudo -su db2inst1 id

gives me correct output. So it must be something about the ()

给我正确的输出。所以它一定是关于 ()

UPDATE I

更新我

If I try

如果我尝试

sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \(1995\)

I get

我得到

/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `/opt/ibm/db2/V9.7/bin/db2 force application (1995)'

UPDATE II

更新二

running /opt/ibm/db2/V9.7/bin/db2 force application (1995)as db2inst1 user gives me the same error but running

/opt/ibm/db2/V9.7/bin/db2 force application (1995)以 db2inst1 用户身份运行给了我同样的错误,但正在运行

/opt/ibm/db2/V9.7/bin/db2 "force application (1995)"

works fine

工作正常

UPDATE III

更新三

the right syntax is

正确的语法是

sudo -su db2inst1 '/opt/ibm/db2/V9.7/bin/db2 "force application (1995)"'

回答by Random832

Since you've got both the shell that you're typing into and the shell that sudo -sruns, you need to quote or escape twice. (EDITED fixed quoting)

由于您拥有正在输入的 shell 和sudo -s运行的 shell ,因此您需要引用或转义两次。(编辑固定引用)

sudo -su db2inst1 '/opt/ibm/db2/V9.7/bin/db2 force application \(1995\)'

or

或者

sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \\(1995\\)

Out of curiosity, why do you need -s? Can't you just do this:

出于好奇,你为什么需要 -s?你不能这样做:

sudo -u db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \(1995\)

回答by user541686

Try

尝试

sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \(1995\)