What is the config file for the sh shell on OS X? (i.e., ~/.bash_profile for bash shell, etc)

6,243

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.

Share:
6,243

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    R uses the /bin/sh shell environment and I'm running scripts (that cannot be modified) that call gfortran-4.8 instead of gfortran so I'm creating an alias. 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 the alias command go?

    EDIT: Also tried adding the alias to ~/.bashrc but that didn't work either.

    • Admin
      Admin almost 9 years
      What is your login or your interactive shell? (perhaps find out with ps $$) If it is bash edit ~/.bashrc
    • Admin
      Admin almost 9 years
      ps $$ outputs bash, and I tried editing ~/.bashrc but that didn't work either
    • Admin
      Admin almost 9 years
      Edit your question to improve it. Don't comment it.
    • Admin
      Admin almost 9 years
      Is there any way to include that on sh shell startup? While that works in Terminal it does not work in R even after executing system('source ~/.bashrc'). R by default requires the sh shell.
    • Admin
      Admin almost 9 years
      You should probably consider checking some .rprofile configurations/customizations, like e.g. this one