JetBrains Gateway 不加载 .bashrc 甚至不加载 /etc/profile.d/*.sh 解决方案
本文最后更新于 411 天前,其中的信息可能已经有所发展或是发生改变。

参考文章:https://youtrack.jetbrains.com/issue/IJPL-166938/Bash-Profile-Not-Loaded-and-Non-Interactive-Run-Shell

JetBrains Gateway 一直有个问题在困扰我,就是它启动的 IDE 不加载我放在 /etc/profile.d 的环境变量,我写在 .bashrc 里的 alias 也不生效。

经过网上冲浪找到原因:JetBrains Gateway 使用非交互式运行 shell,而这种情况下 /etc/profile 并不会加载,并且 .bashrc 文件开头有这么一句:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

当使用非交互式运行的时候,后面的东西就都不会执行了。那么解决方案就很明了了,即把自定义的东西放到 .bashrc 文件的开头,而不是结尾。

而对于 /etc/profile.d/*.sh,我的方案是把我自定义的东西放到单独的文件夹里,比如 /etc/profile.d/dev-container/*.sh,然后在 .bashrc 开头加载。

这样就解决这个问题了。

上一篇
下一篇