What is the config file for the sh shell on OS X? (i.e., ~/.bash_profile for bash shell, etc)
Solution 1
When you start bash with as sh
(for example, if /bin/sh
is a symbolic link to bash
), then the shell will only read /etc/profile
and ~/.profile
. The shell will not read ~/.bash_profile
or ~/.bashrc
.
Search for the phrase "invoked with the name sh" in your bash man page.
Solution 2
When bash is invoked as */sh
, only /etc/profile
and ${HOME}/.profile
are read.
I have these lines in my .profile
(using OS X):
if [ -n "${BASH_VERSION}" ]; then
# include ~/.bashrc if it exists
if [ -f "${HOME}/.bashrc" ]; then
. "${HOME}/.bashrc"
fi
fi
My .bashrc
contains (among other things) these lines:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Now just create a .bash_aliases
file with all your aliases in it.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
R
uses the/bin/sh
shell environment and I'm running scripts (that cannot be modified) that callgfortran-4.8
instead ofgfortran
so I'm creating analias
. I have added the following line to my/etc/profile
and~/.bash_profile
:
alias gfortran-4.8='gfortran'
However, here is the output from Terminal upon calling the alias
gfortran-4.8
:my-MBP:~ myusername$ sh sh-3.2$ gfortran-4.8 --version sh: gfortran-4.8: command not found
Calling
gfortran
works just fine:sh-3.2$ gfortran --version gfortran: warning: couldn’t understand kern.osversion ‘14.4.0 GNU Fortran (GCC) 4.9.0 Copyright (C) 2014 Free Software Foundation, Inc.
If not
/etc/profile
or~/.bash_profile
, where should thealias
command go?EDIT: Also tried adding the alias to
~/.bashrc
but that didn't work either.-
Admin almost 9 yearsWhat is your login or your interactive shell? (perhaps find out with
ps $$
) If it isbash
edit~/.bashrc
-
Admin almost 9 years
ps $$
outputsbash
, and I tried editing~/.bashrc
but that didn't work either -
Admin almost 9 yearsEdit your question to improve it. Don't comment it.
-
Admin almost 9 yearsIs there any way to include that on
sh
shell startup? While that works in Terminal it does not work inR
even after executingsystem('source ~/.bashrc')
.R
by default requires thesh
shell. -
Admin almost 9 yearsYou should probably consider checking some
.rprofile
configurations/customizations, like e.g. this one
-