The behaviour of
echo '\033'
Depends on the implementation and/or the environment.
With UNIX-compliant implementations, it outputs a ESC character followed by NL, in some others, it outputs \033
followed by NL. Some support a -e
option for those \033
escape sequences to be expanded.
Your script has a #! /bin/bash
she-bang, but you're running the script as sh the-script
, so sh
interprets it, not bash
.
On most systems, bash
's echo
builtin doesn't expand \x
sequences by default. It only does so when the xpg_echo
option is enabled or by using the -e
option (unless both the xpg_echo
and posix
options have been enabled).
Probably your local sh
implementation is a UNIX-compliant one in that regard (like dash
, or bash
compiled with the xpg_echo
option enabled by default), but the one on the remote server is not (like bash
).
If you want a portable and reliable behaviour, use printf
instead:
printf '[\33[01;32m green \33[01;37m]\n'
printf '[\33[01;31m red \33[01;37m]\n'