Estou comecando a aprender shell script e estou fazendo alguns scripts simples para treinar. O script abaixo testa se quem esta executando o script esta logado como 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
O resultado e o seguinte:
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$
O problema e que quando eu tento executar como root usando o comando sudo
, o comando echo
nao entende o -e
como argumento e imprime na tela isso:
-e
You are the superuser
Sim eu sei, e um problema besta mas estou curioso para saber o porque que isso acontece. Alguma ideia? Como posso corrigir?
Me desculpem pelos acentos, o meu teclado ainda nao esta configurado.