"bash: export: ... not a valid identifier" 在 git-bash shell "MINGW64" 的 CLI 中 Windows 10

"bash: export: ... not a valid identifier" in CLI of git-bash shell "MINGW64" on Windows 10

使用 git for Windows,打开新的 git-bash 终端时,我总是得到以下输出:

bash: export: `C:\Users\username\Projects\proj1\src\packages\;C:\Users\username\Projects\proj2\MachineLearning\;C:\Users\username\Projects\proj2\MachineLearning\azure_components\': not a valid identifier

接下来,我通过 echo $PATH 检查了 PATH 变量:

C:\Users\username\Projects\proj1-venv/Scripts:/c/Users/username/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/username/bin:/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/users/username/.pyenv/pyenv-win/versions/3.9.0a4/Scripts:/c/Program Files/PuTTY:/c/Program Files/Amazon/AWSCLIV2:/c/ProgramData/chocolatey/lib/gsudo/bin:/c/Program Files/Amazon/AWSSAMCLI/bin:/c/Users/username/AppData/Local/Terraform:/c/Users/username/AppData/Local/iPython:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Microsoft SQL Server/130/Tools/Binn:/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/150/DTS/Binn:/c/Program Files/Azure Data Studio/bin:/c/Users/username/.pyenv/pyenv-win/bin:/c/Users/username/.pyenv/pyenv-win/shims:/c/Users/username/.pyenv/pyenv-win/bin:/c/Users/username/.pyenv/pyenv-win/shims:/c/Users/username/AppData/Local/Microsoft/WindowsApps:/c/Users/username/AppData/Local/Programs/Microsoft_VS_Code/bin:/c/Users/username/.pyenv/pyenv-win/bin:/c/Users/username/.pyenv/pyenv-win/shims:/c/Users/username/AppData/Local/Pandoc:/c/texlive/2021/bin/win32:/c/Users/username/AppData/Local/Terraform:/c/Users/username/AppData/Local/iPython:/c/Users/username/.dotnet/tools:/c/Program Files/Azure Data Studio/bin:/usr/bin/vendor_perl:/usr/bin/core_perl

我尝试使用 export $PATH 显式导出 $PATH 的内容,但多次抛出相同的错误 bash: export: ... not a valid identifier

bash: export: `C:\Users\username\Projects\proj1-venv/Scripts:/c/Users/username/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/username/bin:/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/users/username/.pyenv/pyenv-win/versions/3.9.0a4/Scripts:/c/Program': not a valid identifier
bash: export: `Files/PuTTY:/c/Program': not a valid identifier
bash: export: `Files/Amazon/AWSCLIV2:/c/ProgramData/chocolatey/lib/gsudo/bin:/c/Program': not a valid identifier
bash: export: `Files/Amazon/AWSSAMCLI/bin:/c/Users/username/AppData/Local/Terraform:/c/Users/username/AppData/Local/iPython:/c/Program': not a valid identifier
bash: export: `Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program': not a valid identifier
bash: export: `Files/Microsoft': not a valid identifier
bash: export: `Server/130/Tools/Binn:/c/Program': not a valid identifier
bash: export: `Files/Microsoft': not a valid identifier
bash: export: `Server/Client': not a valid identifier
bash: export: `SDK/ODBC/170/Tools/Binn:/c/Program': not a valid identifier
bash: export: `(x86)/Microsoft': not a valid identifier
bash: export: `Server/150/DTS/Binn:/c/Program': not a valid identifier
bash: export: `Files/Azure': not a valid identifier
bash: export: `Studio/bin:/c/Users/username/.pyenv/pyenv-win/bin:/c/Users/username/.pyenv/pyenv-win/shims:/c/Users/username/.pyenv/pyenv-win/bin:/c/Users/username/.pyenv/pyenv-win/shims:/c/Users/username/AppData/Local/Microsoft/WindowsApps:/c/Users/username/AppData/Local/Programs/Microsoft_VS_Code/bin:/c/Users/username/.pyenv/pyenv-win/bin:/c/Users/username/.pyenv/pyenv-win/shims:/c/Users/username/AppData/Local/Pandoc:/c/texlive/2021/bin/win32:/c/Users/username/AppData/Local/Terraform:/c/Users/username/AppData/Local/iPython:/c/Users/username/.dotnet/tools:/c/Program': not a valid identifier
bash: export: `Files/Azure': not a valid identifier
bash: export: `Studio/bin:/usr/bin/vendor_perl:/usr/bin/core_perl': not a valid identifier

我怀疑它与许多路径中的space字符有关,这在Windows上很常见,但不喜欢UNIX 系统。

假设这是罪魁祸首,我该如何最好地解决这个问题? 如果其他原因导致了这种不良行为,我也想理解。

正如@Zilog80 在我的 OP 下的第一条评论中正确指出的那样,我必须在以下 bash 开始的 export-命令之后检查并删除所有 $ -up 脚本:

  1. .bashrc
  2. .bash_profile
  3. .个人资料

在我的例子中,所有的大惊小怪都归结为我的 ~/.bashrc - 脚本中的以下行:

export $PYTHONPATH

这必须替换为

export PYTHONPATH

现在,打开一个新的终端会话不会再抛出这些 "bash: export: … not a valid identifier" - 错误。