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

What does `[[ -e ~/.profile ]] ` mean in zsh shell?

我想在登录时加载 zsh ~/.profile。我发现了这个 zsh-not-hitting-profile

Gilles 的回答在 ~/.zprofle 中添加了 emulate sh -c '. ~/.profile' 确实有效。

但我想知道为什么 Frank Terbeck 会添加它:

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

我对linux不是很熟悉shell所以听不懂他说的:

And it's only active during the source. So you do not have to save the current option state in order to replay it again after sourcing.

  1. 仅在源期间有效?我需要 ~/.profile 总是需要 source ,我不明白意思,因为 emulate sh -c 'source ~/.profile 每次登录时都有效。
  2. 保存当前选项状态以便重播?什么是选项状态,为什么我需要重播?

[[ -e ~/.profile ]] 只是测试文件 ~/.profile 是否存在。这样,如果文件不存在,您在执行 source ~/.profile 时就不会出错。

"only active during the source" 表示您为 emulate 命令提供的 -c 选项不会更改原始 shell 过程的选项。它只是在模拟 source 命令期间临时使用它。