2

I have replaced sh with zsh with the following commands:

$ sudo mv /bin/sh /bin/sh1
$ sudo ln -s /usr/bin/zsh /bin/sh
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 12 Jul  6 20:48 /bin/sh -> /usr/bin/zsh
$ which sh
/bin/sh
$ sh
$ exit
$ zsh
mpc% exit

As you can see, the sh command doesn't open a zsh shell although it has been linked. The question is why? How can I fix that?

2
  • Expecting all those existing bash scripts to suddenly work with zsh is unrealistic. slopjong.de/2012/07/02/compatibility-between-zsh-and-bash Commented Jul 6, 2018 at 19:48
  • That is not an issue here, steve. This is Ubuntu. /bin/sh has not been expected to be the Bourne Again shell for 12 years, since version 6.10. Commented Jul 7, 2018 at 6:09

2 Answers 2

7

It's supposed to do that. If you start it as sh, it assumes you want something that's mostly compatible with other shells called sh, and runs in a compatibility mode.

See http://zsh.sourceforge.net/Doc/Release/Invocation.html#Compatibility:

Zsh tries to emulate sh or ksh when it is invoked as sh or ksh respectively; [...]

In sh and ksh compatibility modes the following parameters are not special and not initialized by the shell: ... prompt, PROMPT, ...

The usual zsh startup/shutdown scripts are not executed.

I'm not sure if it's possible to have not work in compatibility mode when called as sh, but that might break a number of scripts on your system that assume /bin/sh is just sh, not Zsh.

Probably best to run it as zsh instead.

1
  • Correct, if called sh, it is mostly shell compatible, but slower. So you may suffer from longer boot times. Commented Jul 6, 2018 at 17:19
4

Why not change your user's default shell using chsh instead.

$ chsh -s /usr/bin/zsh

References

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.