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

538 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.