How to get shell to self-detect using zsh or bash

前端 未结 8 915
再見小時候
再見小時候 2020-12-08 09:20

I\'ve a question on how to tell which shell the user is using. Suppose a script that if the user is using zsh, then put PATH to his .zshrc and if using bash sho

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 09:36

    Here is how I am doing it based on a previous answer from Gilles :

    if [ -n "$ZSH_VERSION" ]; then
      SHELL_PROFILE="$HOME/.zprofile"
    else
      SHELL_PROFILE="$HOME/.bash_profile"
    fi
    echo "export VAR1=whatever" >> $SHELL_PROFILE
    echo "INFO: Refreshing your shell profile: $SHELL_PROFILE"
    if [ -n "$ZSH_VERSION" ]; then
      exec zsh --login
    else
      source $SHELL_PROFILE
    fi
    

提交回复
热议问题