Bash scripts requiring sudo password

前端 未结 4 1103
北海茫月
北海茫月 2021-01-31 07:58

I\'m creating a Bash installer script which compiles and installs some libraries for both OSX and Linux. Because some commands in my script (\"make install\", \"apt-get install\

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-31 08:49

    Another way to go about it :

    function checkSudo() {
        if ((EUID != 0)); then
            echo "Granting root privileges for script ( $SCRIPT_NAME )"
            if [[ -t 1 ]]; then
                sudo "$0" "$@"
            else
                exec 1>output_file
                gksu "$0" "$@"
            fi
            exit
        fi
    }
    

提交回复
热议问题