Mithril Mithril - 1 year ago 76
Bash Question

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

I wanted to make zsh load

at login. And I found this zsh-not-hitting-profile

Gilles's answers adding
emulate sh -c '. ~/.profile'

does work.

But I wonder why Frank Terbeck make an addition to it:

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

I am not very familiar with linux shell so I don't understand what he says:

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. only active during the source? I need
    always need to be source , I can't get the meaning, because
    emulate sh -c 'source ~/.profile
    simply works everytime I logined.

  2. save the current option state in order to replay? what is the option state, why I need to replay?

Answer Source

[[ -e ~/.profile ]] simply tests whether the file ~/.profile exists. This way you won't get an error doing source ~/.profile if the file isn't there.

"only active during the source" means that the -c option that you give to the emulate command doesn't change the options to the original shell process. It just uses that temporarily during the emulation of the source command.