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

前端 未结 8 895
再見小時候
再見小時候 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:30

    the other answers fail with set -u

      if [ ! -z ${ZSH_VERSION+x} ]; then
        echo "this is zsh"
        echo ${(%):-%x}
      elif [ ! -z ${BASH_VERSION+x} ]; then
        echo "this is bash"
        echo $BASH_SOURCE
      else
        echo "not recognized"
      fi
    

提交回复
热议问题