【问题标题】:not valid in this context: PATH+ when source ~/.bash_profile in macos在这种情况下无效:PATH+ when source ~/.bash_profile in macos
【发布时间】:2018-11-21 02:28:38
【问题描述】:

我的 bash_profile 如下:

export PATH+=":/Users/steve/workspace/bash-tools/misc";

当我使用时

source ~/.bash_profile

它说

/Users/style/.bash_profile:export:2: not valid in this context: PATH+

我在谷歌上搜索过,但没有找到,请帮忙

【问题讨论】:

  • 您使用的是 bash 还是 zsh?这看起来像是一条 zsh 错误消息...
  • 我正在使用 zsh。有问题吗?

标签: macos terminal


【解决方案1】:

zsh 的export 命令不支持+= 运算符,只支持=。执行此操作的标准方法是显式包含旧的 PATH 值:

export PATH="$PATH:/Users/steve/workspace/bash-tools/misc"

...但是还有另一个问题。您说这是在您的 bash_profile 中,并且这明确是一个 bash 初始化文件,而不是 zsh。如果您希望设置在 bash 和 zsh 之间共享,我建议您将实际设置代码放入 ~/.profile (这是 POSIX 登录 shell 的通用启动文件),然后 sourceing 它来自单独的 ~/.zprofile 和 ~/.bash_profile 文件,如下所示:

[ -f ~/.profile ] || source ~/.profile

这样,您还可以在 ~/.zprofile 文件中添加 zsh-only 设置,在 ~/.bash_profile 文件中添加 bash-only 设置,并且仍然让它们共享大部分设置。

另一方面,如果你只使用 zsh,那么只需将它放在 ~/.zprofile 中即可。

【讨论】:

  • 您能否详细说明如何操作,我不太了解该操作的步骤
  • @SteveLam 要修复您遇到的错误,请将 bash_profile 中的 export 命令替换为我上面给出的命令。要修复您的个人资料设置......这要复杂得多。我必须更多地了解您使用的 shell 和用途,以及您当前的 init 文件中的内容,以便为您提供比我上面所做的更多的建议。
猜你喜欢
  • 2019-12-14
  • 1970-01-01
  • 2017-08-09
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多