我正在尝试执行
sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application (1995)
但我收到此错误bash: syntax error near unexpected token
('`
sudo -su db2inst1 id
给我正确的输出。所以它必须是关于()
的东西如果我尝试
sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \(1995\)
我得到了
/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)'
运行/opt/ibm/db2/V9.7/bin/db2 force application (1995)
作为db2inst1用户给出了同样的错误,但正在运行
/opt/ibm/db2/V9.7/bin/db2 "force application (1995)"
工作正常
正确的语法是
sudo -su db2inst1 '/opt/ibm/db2/V9.7/bin/db2 "force application (1995)"'
答案 0 :(得分:19)
既然您已经输入了要输入的shell和sudo -s
运行的shell,那么您需要引用或转义两次。 (编辑固定报价)
sudo -su db2inst1 '/opt/ibm/db2/V9.7/bin/db2 force application \(1995\)'
或
sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \\\(1995\\\)
出于好奇,你为什么需要-s?你能不能这样做:
sudo -u db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \(1995\)
答案 1 :(得分:3)
尝试
sudo -su db2inst1 /opt/ibm/db2/V9.7/bin/db2 force application \(1995\)