You are not logged in.
I noticed that, despite in my system the sh executable is actually a symlink to bash:
$ ll `which sh`
lrwxrwxrwx 1 root root 4 Feb 13 20:41 /usr/bin/sh -> bashit seem that launching sh does not parse the .bashrc. Adding `echo Processing .bashrc` on top of my .bashrc and manually opening a shell I get:
[mori@stryke ~]$ bash
Processing .bashrc
[mori@stryke ~]$ echo $SHELL
/bin/bash
[mori@stryke ~]$ sh
sh-5.0$ echo $SHELL
/bin/bash
sh-5.0$$ sh --version
GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
sh-5.0$So it seems that under the hood there's always a bash shell, but it seems that launching it using the sh symlink it is configured in a different way. Maybe the bash executable checks its argv[0] and configures itself as a sh shell when launched with the sh symlink? This is the only explanation I can imagine, but it seems weird...
Offline
This is precisely what happens
--norc Do not read and execute the personal initialization file ~/.bashrc if the shell is interactive. This option is on by default if the shell is invoked as sh.
...
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.When bash is started in posix mode, as with the --posix command line option, it follows the POSIX standard for startup files. In this mode, interactive shells expand the ENV variable and commands
are read and executed from the file whose name is the expanded value. No other startup files are read.
Last edited by V1del (2020-02-26 12:33:23)
Offline
@V1del thank you. Do you know if there is an equivalent for .bashrc that is executed automatically when launching with sh? (I'm fighting with an IDE that launches commands in a docker container with /bin/sh, but I'd need to source an environment setting file before the command is executed and I can't figure out how).
Offline
See the edited and added in paragraph
Offline