1

I am using i3, and by default, it uses sh when starting process with the i3 config exec command. This is fine and dandy, but that means the environmental variables created in my .zshrc do not get carried over to child process of i3 (pretty much any program I open).

To fix this, I tried changing the /bin/sh symbolic link to point to /bin/zsh instead like so:

$ which sh
/bin/sh
$ sudo rm /bin/sh
$ sudo ln -s /bin/zsh /bin/sh

This creates the symbolic link I expected it to:

$ ls -la /bin/sh    
lrwxrwxrwx 1 root root 8 Mar 13 22:16 /bin/sh -> /bin/zsh
$ which sh
/bin/sh

However, when I try to run sh, sh starts intead of zsh. The same occurs when I run /bin/sh. I logged out and then logged back in. It did not change anything.

/bin/zsh and zsh commands start zsh as expected.

  • 3
    From the manual page: "Zsh tries to emulate sh or ksh when it is invoked as sh or ksh respectively" - are you sure that's not what's happening here? – steeldriver Mar 14 at 2:48
  • Wow, you are completely correct. Sorry, I should have looked more carefully at the man page or experimented with the shell more. – James Mchugh Mar 14 at 2:53
  • It's still a fair question imho - in particular, perhaps one of the shell experts might be able to explain exactly what features/behviors are and are not emulated – steeldriver Mar 14 at 2:56
  • @steeldriver Interestingly enough though, it seems to mimic sh to the point that it doesn't even look at the .zshrc file, so none of my environmental variables get setup. Maybe I'll just explicitly use exec zsh -c "some command" in the i3 config file instead. – James Mchugh Mar 14 at 3:45
2

It turns out zsh was launching properly, but it was mimicking sh. I should have read the man page more carefully. As @steeldriver pointed out, the man page states: "Zsh tries to emulate sh or ksh when it is invoked as sh or ksh respectively"

  • 1
    Yeah, that's kinda the point of /bin/sh, to be the POSIX shell. – Kusalananda Mar 14 at 8:22
  • @Kusalananda I see that now. Without reading the man page, I don't think it is straight forward to assume that an application would launch differently based on the name of the symbolic link to it. As a user with about a medium level of Linux experience, I would assume that symbolic link would launch an application the same way regardless of the name of the symbolic link. I now see that that is not true. Would the same behavior be expected if /usr/bin/zsh was copied to /bin/sh? – James Mchugh Mar 15 at 4:35
  • The same behaviour would be expected. The /bin/sh shell (no matter what shell actually implements it) is expected to be a POSIX shell capable of running standard compliant shell scripts. Your issue with the environment variables has nothing to do with what shell is being used. You are expecting i3 to know about your variables even though i3 itself never inherited them from your .zshrc file (it was not started from an environment where that file had been parsed, obviously). – Kusalananda Mar 15 at 6:46
  • Since this particular question is about the behaviour of zsh when started as sh, I'd suggest that you open a new question about the issue with the environment variables specifically. You would describe how your start i3 and what you expect to happen with regards to environment variables when you launch child processes from its config (and what actually does happen instead). – Kusalananda Mar 15 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.