【问题标题】:if .bash_profile usually source .bashrc any way, why not just use .bashrc?如果 .bash_profile 通常以任何方式获取 .bashrc,为什么不直接使用 .bashrc?
【发布时间】:2009-05-26 01:13:33
【问题描述】:

看来我们会放

source ~/.bashrc

无论如何,在我们的 .bash_profile 中。那么为什么不只使用一个文件,比如 .bashrc 呢?

【问题讨论】:

    标签: bash .bash-profile


    【解决方案1】:

    因为您可能只想在每次登录时执行一次(所以在 .bash_profile 中)而不是每次打开 xterm 或类似内容时(按照 .bashrc),例如要求用户输入密码解密 SSH 密钥并将其加载到 ssh 代理等中。

    【讨论】:

      【解决方案2】:

      您可以在.bash_profile 中添加一些不适合非终端的shell 实例的内容。例如,如果您通过 shell 从编辑器运行外部命令 - shell 实例的来源是.bashrc,而不是.bash_profile。例如,我可能会将 alias ls=ls -F 放在我的个人资料中,但您不希望该别名仅应用于 shell 的任何实例,而只是应用于您将与之交互的实例。

      【讨论】:

      • 只是想注意 RC 文件只能在交互式 shell 上读取(除非强制或不同的启动模式,如 POSIX 模式或 sh)。
      猜你喜欢
      • 2013-10-15
      • 2018-04-24
      • 2010-09-29
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      相关资源
      最近更新 更多