代码之家  ›  专栏  ›  技术社区  ›  Mithril

`[[-e~/.profile]]`在zsh shell中是什么意思?

  •  0
  • Mithril  · 技术社区  · 8 年前

    我想加载zsh ~/.profile 登录时。我找到了这个 zsh-not-hitting-profile

    Gilles的答案添加 emulate sh -c '. ~/.profile' 在里面 ~/.zprofle 确实有效。

    但我想知道为什么Frank Terbeck会在其中添加:

    [[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'

    我对linux shell不太熟悉,所以我不明白他说什么:

    它仅在源代码期间处于活动状态。因此,您不必保存当前选项状态,以便在寻源后再次回放。

    1. 仅在源代码期间有效?我需要 ~/.配置文件 总是需要成为源头,我无法理解其含义,因为 emulate sh -c 'source ~/.profile 每次登录都能正常工作。
    2. 保存当前选项状态以便重播?选项状态是什么,为什么我需要重播?
    1 回复  |  直到 8 年前
        1
  •  1
  •   Barmar    8 年前

    [[ -e ~/.profile ]] 只需测试文件是否 ~/.profile 存在。这样做不会出错 source ~/.profile 如果文件不在那里。

    “仅在源代码期间有效”是指 -c 您提供给 emulate 命令不会将选项更改为原始shell进程。它只是在模拟 source 命令