learning shell script prompt to run with superuser privileges (4)
Shell script prompt to run with superuser privileges
【Purpose】
Check whether have root privileges to run script
【Eevironment】
Ubuntu 16.04 bash env
【Procdeure】
Source code:
#!/bin/bash if [[ $EUID != 0 ]]; then echo "This script requires root privileges, trying to use sudo" sudo "./tmp.sh" "$@" fi
Test method:
vmuser@vmuser-virtual-machine:~/shell$ ./tmp.sh
This script requires root privileges, trying to use sudo
[sudo] password for vmuser: