How to get default shell

前端 未结 5 687
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 02:56

We can run something like chsh -s /usr/local/bin/zsh to set a new default shell. Is there a command we can run to know what that shell is?

I don’t mean

5条回答
  •  醉梦人生
    2020-12-08 03:10

    For macOS:

    dscl . -read /Users/username UserShell
    

    For the current macOS user:

    dscl . -read ~/ UserShell
    

    To parse the path inline using sed:

    dscl . -read ~/ UserShell | sed 's/UserShell: //'
    

    Using $SHELL will report the current login shell, not the default login shell. In certain cases, these are not the same. For example, when working in an IDE such as Visual Studio Code which opens an integrated terminal without consulting the default shell.

    In addition, as pointed out by Martin C. Martin, $SHELL is a constant that will not change after chsh changes the default login shell.

提交回复
热议问题