4

If I do ls -l /bin/sh: I get

lrwxrwxrwx 1 root root 4 Jan  9 00:01 /bin/sh -> bash

However, when I start sh, I get a completely different prompt than I would, my ~/.bashrc isn't sourced, and if I manually source it I get a bunch of syntax errors.

What gives? I assume this is some compatibility mode?

Edit:

Running Endeavour OS (arch-based)

echo $PATH gives:

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

Yes, /usr/bin/sh is a symlink to bash too.

2
  • What OS/Distro? What is the output of "echo $PATH"? Does running /bin/sh behave the same way as running sh ? Do you have a /usr/bin/sh - and if so is that also a symlink?
    – davidgo
    Jan 19, 2022 at 5:39
  • Edited original question. Jan 19, 2022 at 6:02

1 Answer 1

3

Yes, when invoked as sh, bash goes into full Bourne shell compatibility mode. From the man page:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior. When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect. A non-interactive shell invoked with the name sh does not attempt to read any other startup files. When invoked as sh, bash enters posix mode after the startup files are read.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .