learning shell script prompt to run with superuser privileges (4)

Shell script prompt to run with superuser privileges

Purposeshell

       Check whether have root privileges to run scriptbash

 

Eevironmentui

       Ubuntu 16.04 bash envspa

 

Procdeurecode

  Source code:blog

#!/bin/bash
if [[ $EUID != 0 ]]; then
echo "This script requires root privileges, trying to use sudo"
sudo "./tmp.sh" "$@"
fi

 

  Test method:ip

vmuser@vmuser-virtual-machine:~/shell$ ./tmp.sh 
This script requires root privileges, trying to use sudo
[sudo] password for vmuser:it

相關文章
相關標籤/搜索