Bash – Fix Syntax Error Near Unexpected Token ‘(‘

bashlinuxterminalUbuntu

I'm working on saving high scores for my Game Elf JAMMA board (412-in-1). I'm currently following this tutorial. I'm trying to run this command

mv hiscore(pre_mame0133u1).dat /mnt/three/usr/local/share/xmame/hiscore.dat

but as you can see in my screenshot, it's returning an error

bash: syntax error near unexpected token '('

Best Answer

bash: syntax error near unexpected token '('

You need to escape the brackets:

mv hiscore\(pre_mame0133u1\).dat /mnt/three/usr/local/share/xmame/hiscore.dat

Note:

For future reference you can use ShellCheck to find bugs in your bash code. Entering the uncorrected script gives the following:

$ 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?

Correcting the first error:

$ 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?

And correcting the second error:

$ 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.

Further Reading

Related Question