简体   繁体   中英

Difference of "zsh" vs "source zsh" in ".bashrc"

Amazon recommends adding zsh to .bashrc to change default shell for AWS CloudShell, since chsh somehow doesn't work. As I understand correctly, zsh runs in a child process. I wonder if I could add source zsh to .bashrc instead, since I'd like one less process as a minimalist.

I think you mean exec zsh , not source zsh , since source processes the file as a set of bash statements, and therefore can't be used with binaries.

You can do it, but some caution is advised:

Assume that you have in this way established an interactive zsh, in which you work, and at one time during your work, you want to create an interactive bash subshell (maybe for playing around with some bash commands). If you have a plain exec zsh in your.bashrc, your invocation of bash would again result in a zsh - not what you want.

In order to avoid this, you can use a guard in your.bashrc, like this:

if [[ -z ${bash_zsh_guard:-} ]]
then
  export bash_zsh_guard=NO
  exec zsh
fi

In your "top level" aws bash, this will replace the bash process by zsh, but in any child bash process, you will stick with bash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM