0

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.

Diego
  • 867
  • 7
  • 13
  • 5
    Not familiar with `aws`, but in most unix environments, `exec` will launch a process that replaces the current process. So it's possible that `exec zsh` would work. – Gairfowl Jul 25 '22 at 00:22
  • 2
    The argument to `source` has to be a shell script, not a binary program. – Barmar Jul 25 '22 at 01:32

1 Answers1

3

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.

user1934428
  • 19,864
  • 7
  • 42
  • 87