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

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

    Myself having a similar problem, settled for:

    _shell="$(ps -p $$ --no-headers -o comm=)"                                                                                                       
    if [[ $_shell == "zsh" ]]; then                                                                                                                  
        read -q -s "?Do it?: "                                                                                                                    
    fi                                                                                                                                               
    elif [[ $_shell == "bash" || $_shell == "sh" ]]; then                                                                                              
        read -n 1 -s -p "Do it [y/n] "                                                                                                            
    fi                                                                                                                                               
    

提交回复
热议问题