Alias defined in .bash_profile not working in OS X

后端 未结 2 1208
滥情空心
滥情空心 2021-01-13 08:19

I have defined three aliases in my .bash_profile but my bash shell is not reading it. The aliases defined are not working in my terminal and I couldn\'t resolve

2条回答
  •  别那么骄傲
    2021-01-13 09:12

    Assuming:

    • you use OS X's native terminal, Terminal.app, or popular alternative iTerm2
    • and bash is indeed your shell (as is the default on OS X)

    then ~/.bash_profile should be loaded for every interactive shell, because both terminal programs create login shells by default.
    Bash login shells source ~/.bash_profile, but not ~/.bashrc.

    Note that this differs from most Linux distros, where a single login shell is executed on startup, and later interactive shells are non-login shells, which only load ~/.bashrc, not ~/.bash_profile.
    A frequently seen technique to ensure that definitions are loaded in both login and non-login interactive shells is to place definitions in ~/.bashrc, and then source it from ~/.bash_profile, using the following line:
    [[ -f ~/.bashrc ]] && . ~/.bashrc


    You can create a login shell on demand by executing bash -l from an existing shell; if that loads your aliases, then the problem must be with what your default shell is and/or how your terminal program is configured.

    • echo $SHELL tells you what your default shell is.
    • if you use Terminal.app, Terminal > Preferences..., tab General, setting Shells open with tells you whether the default shell or a custom shell is being used.

提交回复
热议问题