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:

 

posted @ 2019-01-24 14:15  嵌入式实操  阅读(319)  评论(0编辑  收藏  举报