The problem is in the title, but let me add few details here.
I am running on OS X 10.10.5 (14F27)
. Using default Terminal.app
.
Content of config files
Content of /etc/profile
echo " # reading /etc/profile"
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
Content of /etc/bashrc
echo " # reading /etc/bashrc"
# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
return
fi
PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL,
# including the host name to disambiguate local vs.
# remote connections. Percent-escape spaces.
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
printf '\e]7;%s\a' "$PWD_URL"
}
PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi
Content of ~/.profile
echo " # reading ~/.profile"
...
Content of ~/.bashrc
echo " # reading ~/.bashr"
...
source /etc/profile
...
Content of ~/.bash_profile
echo " # reading ~/.bash_profile"
source ~/.profile
source ~/.bashrc
Output of calling sh
and bash
So here is output of invoking sh
.
$ sh
sh-3.2$
sh --login
# reading /etc/profile
# reading /etc/bashrc
# reading ~/.profile
d12frosted:~ d12frosted$
$ bash
# reading ~/.bashr
# reading /etc/profile
# reading /etc/bashrc
d12frosted:~ d12frosted$
$ bash --login
# reading /etc/profile
# reading /etc/bashrc
# reading ~/.bash_profile
# reading ~/.profile
# reading ~/.bashr
# reading /etc/profile
# reading /etc/bashrc
d12frosted:~ d12frosted$
As you can see, when calling sh
– it doesn't load any configurations. Is something broken in my environment or it's expected?
Best Answer
This is expected sh only loads ~/.profile when it is a login shell.
From Bash reference manual
Of you want bash running as sh to use ~/.profile when not a login shell (e.g. keep current environment) use