4
I’m starting to learn shell script and am doing some simple scripts to train. The script below tests whether whoever is 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 and 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 the -e
as argument and print on screen that:
-e
You are the superuser
Yes I know, and a stupid problem but I’m curious to know why it happens. Any idea? How can I fix?
Sorry for the accents, my keyboard is not yet configured.
Perfect! It worked. Thank you very much, it was worth taking this doubt.
– rafaelpfreire