.bashrc 中意外标记“(”附近出现语法错误

.bashrc 中意外标记“(”附近出现语法错误
-bash: /root/.bashrc: line 100: syntax error near unexpected token `('
-bash: /root/.bashrc: line 100: `export PATH=/bin/lscript:/bin/lscript:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Intel/TXE Components/iCLS/:/mnt/c/Program Files/Intel/TXE Components/iCLS/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/Program Files/Intel/TXE Components/DAL/:/mnt/c/Program Files (x86)/Intel/TXE Components/DAL/:/mnt/c/Program Files/Intel/TXE Components/IPT/:/mnt/c/Program Files (x86)/Intel/TXE Components/IPT/:/mnt/c/Program Files/Intel/WiFi/bin/:/mnt/c/Program Files/Common Files/Intel/WirelessCommon/:/mnt/c/Program Files (x86)/GtkSharp/2.12/bin:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files (x86)/QuickTime/QTSystem/:/mnt/c/Program Files/PuTTY/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Git/mingw64/bin:/mnt/c/Program Files/Git/usr/bin:/mnt/c/Users/User/AppData/Local/Microsoft/WindowsApps:/snap/bin'

答案1

您要分配的值中有未加引号的空格。bash使用空格来表示一个参数的结束位置和下一个参数的开始位置,并将括号 (" ()") 视为特殊符号。因此,

export PATH=/bin/lscript:/bin/lscript:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Intel/TXE Components/iCLS/:/mnt/c/Program Files/Intel/TXE Components/iCLS/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/Window`sPowerShell/v1.0/:/mnt/c/Program Files/Intel/TXE Components/DAL/:/mnt/c/Program Files (x86)/Intel/TXE Components/DAL/:/mnt/c/Program Files/Intel/TXE Components/IPT/:/mnt/c/Program Files (x86)/Intel/TXE Components/IPT/:/mnt/c/Program Files/Intel/WiFi/bin/:/mnt/c/Program Files/Common Files/Intel/WirelessCommon/:/mnt/c/Program Files (x86)/GtkSharp/2.12/bin:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files (x86)/QuickTime/QTSystem/:/mnt/c/Program Files/PuTTY/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Git/mingw64/bin:/mnt/c/Program Files/Git/usr/bin:/mnt/c/Users/User/AppData/Local/Microsoft/WindowsApps:/snap/bin

看起来像是bash的赋值有 32 个参数。

有两种解决方案:

  1. 使用 \ 转义每个空格或括号。
  2. 用引号 ("') 括住每个包含空格的参数。

使用第一种方法得到的结果如下:

export PATH=/bin/lscript:/bin/lscript:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program\ Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc:/mnt/c/Program\ Files\ \(x86\)/Common\ Files/Oracle/Java/javapath:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/Program\ Files\ \(x86\)/Intel/TXE\ Components/iCLS/:/mnt/c/Program\ Files/Intel/TXE\ Components/iCLS/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/Program\ Files/Intel/TXE\ Components/DAL/:/mnt/c/Program\ Files\ \(x86\)/Intel/TXE\ Components/DAL/:/mnt/c/Program\ Files/Intel/TXE\ Components/IPT/:/mnt/c/Program\ Files\ \(x86\)/Intel/TXE\ Components/IPT/:/mnt/c/Program\ Files/Intel/WiFi/bin/:/mnt/c/Program\ Files/Common\ Files/Intel/WirelessCommon/:/mnt/c/Program\ Files\ \(x86\)/GtkSharp/2.12/bin:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program\ Files\ \(x86\)/QuickTime/QTSystem/:/mnt/c/Program\ Files/PuTTY/:/mnt/c/Program\ Files/Git/cmd:/mnt/c/Program\ Files/Git/mingw64/bin:/mnt/c/Program\ Files/Git/usr/bin:/mnt/c/Users/User/AppData/Local/Microsoft/WindowsApps:/snap/bin

对于第二种方法,

export PATH=/bin/lscript:/bin/lscript:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:"/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc":"/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath":/mnt/c/ProgramData/Oracle/Java/javapath:"/mnt/c/Program Files (x86)/Intel/TXE Components/iCLS/":"/mnt/c/Program Files/Intel/TXE Components/iCLS/":/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:"/mnt/c/Program Files/Intel/TXE Components/DAL/":"/mnt/c/Program Files (x86)/Intel/TXE Components/DAL/":"/mnt/c/Program Files/Intel/TXE Components/IPT/":"/mnt/c/Program Files (x86)/Intel/TXE Components/IPT/":"/mnt/c/Program Files/Intel/WiFi/bin/":"/mnt/c/Program Files/Common Files/Intel/WirelessCommon/":"/mnt/c/Program Files (x86)/GtkSharp/2.12/bin":/mnt/c/WINDOWS/System32/OpenSSH/:"/mnt/c/Program Files (x86)/QuickTime/QTSystem/":"/mnt/c/Program Files/PuTTY/":"/mnt/c/Program Files/Git/cmd":"/mnt/c/Program Files/Git/mingw64/bin":"/mnt/c/Program Files/Git/usr/bin":/mnt/c/Users/User/AppData/Local/Microsoft/WindowsApps:/snap/bin

相关内容