我正在尝试修改 ~/.profile 中的 PATH:
export PATH=$PATH:/opt/jdk1.8/bin
echo "Path is exported."
我总是通过 SSH 登录,所以这就是为什么我把它放在 ~/.profile 中。我使用 zsh (oh-my-zsh) 作为我的默认 shell,在我的 ~/.zprofile 中我正在采购 ~/.profile:
source ~/.profile
奇怪的是,当我通过 SSH 登录时,我看到“路径已导出。”消息,这意味着源语句 .zprofile 正在运行,但当我回显我的 $PATH 时,缺少“/opt/jdk1.8/bin”。如果我手动获取 ~/.profile 的源,路径会正确更新,所以我不确定为什么它在登录时获取源时不能正确导出路径。如果有帮助的话,这一切都在 vagrant box 中。有什么想法吗?
编辑: zsh -ixc exit 2>&1 | 的输出grep 路径:
+/home/vagrant/.zcompdump:1254> _postpatcomps=( '(p[bgpn]m*|*top[bgpn]m)' _pbm '(texi(2*|ndex))' _texi '(tiff*|*2tiff|pal2rgb)' _tiff '-value-,(ftp|http(|s))_proxy,-default-' _urls '-value-,LC_*,-default-' _locales '-value-,*path,-default-'
_directories '-value-,*PATH,-default-' _dir_list '-value-,RUBY(LIB|OPT|PATH),-default-' _ruby '*/X11(|R<4->)/*'
_x_arguments 'yodl(|2*)' _yodl )
+/home/vagrant/.zshrc:56> export 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games'
+/home/vagrant/.zcompdump-vagrant-ubuntu-trusty-64-5.0.2:1256> _postpatcomps=( '(p[bgpn]m*|*top[bgpn]m)' _pbm '(texi(2*|ndex))' _texi '(tiff*|*2tiff|pal2rgb)' _tiff '-value-,(ftp|http(|s))_proxy,-default-' _urls '-value-,LC_*,-default-' _locales '-value-,*path,-default-'
_directories '-value-,*PATH,-default-' _dir_list '-value-,RUBY(LIB|OPT|PATH),-default-' _ruby '*/X11(|R<4->)/*'
_x_arguments 'yodl(|2*)' _yodl )
+nvm:409> PATH=+nvm:409> nvm_strip_path /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games /bin
+nvm:409> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
+nvm:411> PATH=+nvm:411> nvm_prepend_path /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games /home/vagrant/.nvm/versions/node/v5.0.0/bin
+nvm:411> PATH=/home/vagrant/.nvm/versions/node/v5.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
+nvm:417> MANPATH=+nvm:417> nvm_strip_path /home/vagrant/.nvm/versions/node/v5.0.0/share/man:/usr/local/man:/usr/local/share/man:/usr/share/man:/opt/jdk1.8/man /share/man
+nvm:417> MANPATH=/usr/local/man:/usr/local/share/man:/usr/share/man:/opt/jdk1.8/man
+nvm:419> MANPATH=+nvm:419> nvm_prepend_path /usr/local/man:/usr/local/share/man:/usr/share/man:/opt/jdk1.8/man /home/vagrant/.nvm/versions/node/v5.0.0/share/man
+nvm:419> MANPATH=/home/vagrant/.nvm/versions/node/v5.0.0/share/man:/usr/local/man:/usr/local/share/man:/usr/share/man:/opt/jdk1.8/man
+nvm:420> export MANPATH
+nvm:422> export PATH
+nvm:424> export 'NVM_PATH=/home/vagrant/.nvm/versions/node/v5.0.0/lib/node'
答案1
我明白问题出在哪里了。基于@L。 Levrel 的评论,我在 .zshrc 中添加了一条 echo 语句,因为他说 ssh 登录 shell 既是交互式的又是登录的。果然,.zshrc 在 .zprofile 之后获取,并且路径在 .zshrc 中被覆盖。将 Java 变量的导出命令移至 ~/.zshrc 解决了该问题。