我收到一个 bash: 意外标记附近的语法错误 '('

Ken*_*yon 4 linux terminal bash ubuntu

我正在努力为我的 Game Elf JAMMA 板(412 合 1)保存高分。我目前正在关注本教程。我正在尝试运行此命令

mv hiscore(pre_mame0133u1).dat /mnt/three/usr/local/share/xmame/hiscore.dat
Run Code Online (Sandbox Code Playgroud)

但正如你在我的截图中看到的,它返回了一个错误

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

Dav*_*ill 10

bash: syntax error near unexpected token '('

您需要转义括号:

mv hiscore\(pre_mame0133u1\).dat /mnt/three/usr/local/share/xmame/hiscore.dat
Run Code Online (Sandbox Code Playgroud)

笔记:

为了将来参考,您可以使用ShellCheck查找 bash 代码中的错误。输入未更正的脚本提供以下内容:

$ shellcheck myscript

Line 1:
mv hiscore(pre_mame0133u1).dat /mnt/three/usr/local/share/xmame/hiscore.dat
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
          ^-- SC1036: '(' is invalid here. Did you forget to escape it?
          ^-- SC1088: Parsing stopped here. Invalid use of parentheses?
Run Code Online (Sandbox Code Playgroud)

更正第一个错误:

$ shellcheck myscript

Line 1:
mv hiscore\(pre_mame0133u1).dat /mnt/three/usr/local/share/xmame/hiscore.dat
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
                          ^-- SC1089: Parsing stopped here. Is this keyword correctly matched up?
Run Code Online (Sandbox Code Playgroud)

并纠正第二个错误:

$ shellcheck myscript

Line 1:
mv hiscore\(pre_mame0133u1\).dat /mnt/three/usr/local/share/xmame/hiscore.dat
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
Run Code Online (Sandbox Code Playgroud)

进一步阅读