I'm starting to learn shell script and am doing some simple scripts to train. The script below tests whether anyone running the script is logged in as root.
# !/bin/bash
#
# This script test if you are the superuser
if [ "$(id -u)" = "0" ]; then
echo -e "\nYou are the superuser\n"
exit 0
else
echo -e "\nYou must be the superuser to run this script\n"
exit 1
fi
The result is the following:
rafa@ubuntu:~/Desktop/shell$ ./superuser.sh
You must be the superuser to run this script
rafa@ubuntu:~/Desktop/shell$ sudo ./superuser.sh
-e
You are the superuser
rafa@ubuntu:~/Desktop/shell$
The problem is that when I try to run as root using the command sudo
, the command echo
does not understand -e
as argument and prints on the screen this:
-e
You are the superuser
Yes I know, it's a stupid problem but I'm curious to know why this happens. Any idea? How can I fix it?
I'm sorry for the accents, my keyboard is not yet set up.