macOS Catalina 10.15(beta) - Why is ~/.bash_profile not sourced by my shell?

前端 未结 9 617
北荒
北荒 2020-12-12 10:31

I want to set the environment variable I added below the line to ~/.bash_profile and ~/.profile but it didn\'t work.

export JBOSS_H         


        
相关标签:
9条回答
  • 2020-12-12 10:56

    If you for some reason (as me) don't want to rename/move your ~/.bash_profile file you can do the next things:

    1. Create a new file ~/.zprofile
    2. Type there source ~/.bash_profile
    3. Save and close
    4. Run a new terminal session
    0 讨论(0)
  • 2020-12-12 11:01
    cp zprofile ~/.zprofile
    

    Add to .zprofile:

    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    

    eg. by >vi .zprofile

    Done

    0 讨论(0)
  • 2020-12-12 11:02

    After you close a Terminal window, variables you set in that window are no longer available. If you want the value of a variable to persist across sessions and in all Terminal windows, you must set it in a shell startup script. For information about modifying your zsh shell startup script to keep variables and other settings across multiple sessions, see the “Invocation” section of the zsh man page.

    You can use ~/.zlogin to add your variables.

    Check out this reference.

    0 讨论(0)
  • 2020-12-12 11:09

    I created a new file called

    /usr/local/bin/mybash

    which contains a wrapper script:

    /usr/local/bin/bash --init-file $HOME/.bashrc

    I installed this local/bin/bash from HomeBrew.

    Full Sequence of Events

    brew install bash
    echo "/usr/local/bin/bash --init-file $HOME/.bashrc" > /usr/local/bin/mybash
    chmod +x /usr/local/bin/mybash
    

    Then I opened the settings for terminal.app [cmd-comma]. Under the General Tab, select the radio button for Command (complete path)

    In the text box change the text from /bin/zsh/ to /usr/local/bin/bash.

    0 讨论(0)
  • 2020-12-12 11:09

    You can just copy your existing bash_profile and name it zprofile and it will work fine.

    • Run the below command in terminal and you are set after closing and opening new terminal.

    cp ~/.bash_profile ~/.zprofile

    0 讨论(0)
  • 2020-12-12 11:10

    changing the bash profile to zsh profile works and source it as well to see in action.

    vikas@Vikas-Kumar ~ % mv .bash_profile .zsh_profile
    vikas@Vikas-Kumar ~ % source .zsh_profile
    
    0 讨论(0)
提交回复
热议问题