Hyper终端启动出现bash: export: 无效标识符错误的解决咨询
解决Hyper终端启动时的PATH导出错误
作为编程和Hyper终端新手,每次启动终端都会弹出以下错误,虽然不影响代码运行,但希望彻底消除这些提示:
错误信息
bash: export: `Files(x86)/Common': not a valid identifier bash: export: `Files/Intel/Shared': not a valid identifier bash: export: `Libraries/redist/intel64/compiler:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program': not a valid identifier bash: export: `Files/NVIDIA': not a valid identifier bash: export: `Corporation/NVIDIA': not a valid identifier bash: export: `NvDLISR:/c/Program': not a valid identifier bash: export: `Files(x86)/NVIDIA': not a valid identifier bash: export: `Corporation/PhysX/Common:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program': not a valid identifier bash: export: `Files/dotnet:/c/ProgramData/chocolatey/bin:/cmd:/c/Program': not a valid identifier bash: export: `Files/nodejs:/c/Users/John/AppData/Local/Programs/Python/Python310:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/John/.npm-global/bin:~/.npm-global/bin': not a valid identifier
当前.bashrc文件内容
export NPM_CONFIG_PREFIX=~/.npm-global export PATH=C:/Development/ani-gen/env/Scripts:/c/Users/John/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/John/bin:/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files/dotnet:/c/ProgramData/chocolatey/bin:/cmd:/c/Program Files/nodejs:/c/Users/John/AppData/Local/Programs/Python/Python310:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/John/.npm-global/bin:~/.npm-global/bin
declare -p PATH输出结果
$ declare -p PATH declare -x PATH="/c/Users/John/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/John/bin:/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files/dotnet:/cmd:/c/Program Files/nodejs:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/John/.npm-global/bin:/c/Users/John/.npm-global/bin"
解决办法
问题根源
bash中导出包含空格的路径时,必须用双引号包裹整个PATH值。你当前的export PATH=...没有加引号,bash会把路径中的空格当成参数分隔符,导致它把Program Files这类带空格的路径拆成多个无效的标识符,从而抛出错误。
修复步骤
- 打开你的
.bashrc文件,找到export PATH=...这一行。 - 给整个PATH字符串加上双引号,修改后内容如下:
export NPM_CONFIG_PREFIX=~/.npm-global export PATH="C:/Development/ani-gen/env/Scripts:/c/Users/John/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/John/bin:/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files/dotnet:/c/ProgramData/chocolatey/bin:/cmd:/c/Program Files/nodejs:/c/Users/John/AppData/Local/Programs/Python/Python310:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/John/.npm-global/bin:~/.npm-global/bin"
- 保存文件后,重启Hyper终端,或者执行以下命令让修改立即生效:
source ~/.bashrc
这样启动终端时就不会再弹出那些错误提示了。
内容的提问来源于stack exchange,提问作者TomoDevelops
相关产品推荐
相关产品推荐

