How to make OS X to read .bash_profile not .profile file

后端 未结 6 1097
野性不改
野性不改 2020-12-02 06:53

I have read so many suggestions about, not putting your customization aka commands in \".profile\" file. Rather, create a .bash_profile for yourself and add your alias and e

相关标签:
6条回答
  • 2020-12-02 07:14

    According to Apple,

    zsh (Z shell) is the default shell for all newly created user accounts, starting with macOS Catalina.

    So you should verify your default shell with the command:

    $ echo $SHELL
    

    If the result is /bin/bash your default shell is BASH, and if the result is /bin/zsh the default is ZSH.

    Go to home with $ cd ~/ and create the profile (if it does not exist) and edit it with the commands:

    For bash:

    $ touch .bash_profile
    $ open .bash_profile
    

    For ZSH:

    $ touch .zprofile
    $ open .zprofile
    
    0 讨论(0)
  • 2020-12-02 07:15

    It's also possible that your terminal shell is defaulting to sh instead of bash. You can verify this first:

    $ echo $SHELL
    /bin/tcsh
    

    To change this to bash, you can go into your Terminal -> Preferences -> Startup tab, and change "Shell Opens With:" from "Default login shell" to Command and value "/bin/bash".

    Alternately, you can change your default shell by executing the following command at the command prompt:

    chsh -s bin/bash
    

    After you do one of these, open a new shell window, and your .bash_profile should be sourced.

    0 讨论(0)
  • 2020-12-02 07:20

    I solved by simply adding bash (in a newline) into ~/.bash_profile file.

    0 讨论(0)
  • 2020-12-02 07:33

    According to the manual page that ships with OS X:

    ... it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

    It should only read ~/.profile as a last resort if neither ~/.bash_profile nor ~/.bash_login are readable.

    On all of my OS X systems, I have my ~/.bash_profile set to:

    if [ -f ~/.bashrc ]; then
        source ~/.bashrc
    fi
    

    It is highly recommended that you do this on OS X in order to get bash to read your ~/.bashrc file like you would expect.

    0 讨论(0)
  • 2020-12-02 07:36

    It should be mentioned that bash will first look for a /etc/profile file, as stated in the Bash man pages.

    When bash is invoked as an interactive login shell, or as a non-inter- active shell with the --login option, it first reads and executes com- mands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

    0 讨论(0)
  • 2020-12-02 07:38

    You can use zsh to fix the problem.

    The Z shell (also known as zsh) is a Unix shell that is built on top of bash (the default shell for macOS) with additional features. It's recommended to use zsh over bash.

    Installation

    1. Install zsh using Homebrew: $ brew install zsh
    2. Install Oh My Zsh: $ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    3. Move to .bash_profile setting .zshrc file
    4. To apply the changes you make you need to either start new shell instance or run: source ~/.zshrc
    0 讨论(0)
提交回复
热议问题