echo is a shell builtin in Bash and dash (
/bin/sh). If you run
echo from the command line you are using the Bash builtin, if you are running your shell script with
sh you are using the Dash builtin.
The dash version of
echo doesn't know the
-e option but just outputs anything verbatim without any special handling for
Either use Bash to run your shell script, or use
/bin/echo instead of
/bin/echo -e "\e[1;31mThis is red text\e[0m"
To avoid the problems with different versions of
echo you may want to use
printf instead. In contrast to
printf always interprets
\ sequences but doesn't automatically add a linefeed at the end so you have to append
\n at the end if you want one.
As some versions of
printf don't understand
\e you should use
printf "\033[1;31mThis is red text\033[0m\n"