Bash scripts requiring sudo password

前端 未结 4 1109
北海茫月
北海茫月 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:43

    To get the password, just put sudo echo "Thanks." at the start of the script.

    But I would prefer this solution:

    if [[ $UID != 0 ]]; then
        echo "Please run this script with sudo:"
        echo "sudo $0 $*"
        exit 1
    fi
    

提交回复
热议问题