Here is a simple function that our script uses to find if user is logged in as root.
do_check_user(){
id | grep root 1>/dev/null 2>&1
if test "$?" != "0"
then
echo ""
echo " Invalid login, Please logon as root and try again!"
exit 0
fi
}
I do not completely understand how this function works. I tried some searching online to find bits and parts of how it is implemented. but it is still not clear to me.
Especially these lines:
id | grep root 1>/dev/null 2>&1
if test "$?" != "0"
I tried doing step by step. But I get error
id | grep root 1
grep: 1: No such file or directory
if you could explain me this syntax and what it is doing, it will be very helpful
Thanks