I use the Windows Subsystem For Linux. On launching Ubuntu, I get this errors:

-bash: /home/divyansh/.bashrc: line 119: syntax error near unexpected token `('
-bash: /home/divyansh/.bashrc: line 119: `export PATH=/mnt/z/usr/local/bin:/mnt/z/usr/local/bin:/home/divyansh/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_2004.2020.424.0_x64__79rhkp1fndgsc:/mnt/c/Python38/Scripts:/mnt/c/Python38:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:/mnt/c/Program Files/Intel/WiFi/bin:/mnt/c/Program Files/Common Files/Intel/WirelessCommon:/mnt/c/MinGW/bin:/mnt/c/ProgramData/pbox:/mnt/c/Program Files/nodejs:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/asus/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/asus/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin:/mnt/c/tools:/mnt/c/Users/asus/AppData/Roaming/npm:/mnt/c/Users/asus/AppData/Local/atom/bin:/snap/bin'

The '(' token appears only once in the line

:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:

. I do not understand why this error is caused. What can I do to clear this? If I leave it as it is, how does it affect the respective path variables?

  • What does echo path show? Did you add this entry manually or was it installed by Oracle? – ajgringo619 Aug 15 '20 at 18:41
  • 1
    @ajgringo619, echo path will output just path in almost any shell. echo $path would likely output an empty string in Bash, while echo $PATH, or preferably echo "$PATH" to avoid word-splitting effects, would output the value of the PATH variable. Not that it helps here, the value would just be whatever it was before the failed export command. – ilkkachu Aug 15 '20 at 19:08
  • Doh! How did I miss that! – ajgringo619 Aug 15 '20 at 19:09
  • Quoting the whole string as PATH='/mnt/......' has removed the error on startup. @ajgringo619 No, I don't remember adding this entry manually. I do not know if it was Oracle or Windows that added it. – Divyansh Hardia Aug 15 '20 at 19:20

With regard to the shell syntax, ( is a special character (like ;, >, & etc.), it can't appear as part of an assigned value without being escaped or quoted. It's used e.g. to start subshells, but as you noticed, in most cases it just causes a syntax error. (Unlike, say &, which would just silently end the command.)

However, the parenthesis aren't your only problem, you also have whitespace in the path. That's not a syntax error, but changes the meaning of the command. export PATH=/mnt/c/Program Files/Somepath means to assign /mnt/c/Program to PATH, and to export a variable called Files/Somepath, which also causes an error because the slash is not valid in a variable name.

You'll need to either escape all the parenthesis and spaces, as in Program\ Files\ \(x86\), or simply quote the whole string:

PATH='/mnt/z/usr/local/bin:...:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:...'

or just parts of it, though that may be harder to read:

PATH=/mnt/z/usr/local/bin:...:'/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath':...

(Note that you can't do both inside each other, PATH='/mnt/c/Program\ Files\ \(x86\)/...' would assign a string containing literal backslashes.)


Add an escape character \ before each parenthesis:

Program Files \(x86\)/

  • 2
    Escaping the parentheses is a good solution. Another option is to quote the quote the string. – Andy Dalton Aug 15 '20 at 18:57
  • 8
    The string also contains a number of spaces, which will also cause trouble. It's be better to quote the whole thing. – Gordon Davisson Aug 15 '20 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.