domain="www.google.com"
echo -e "\e[1;34m"$domain"\e[0m"
I expected this to output www.google.com
in green letters.
Instead I got
-e \e[1;34mwww.google.com\e[0m
Depending the environment or shell used can have an effect, one thing you could probably do is to use ANSI-C
quoting:
echo $'\e[1;34m'${domain}$'\e[0m'
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.
https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
\033
instead of \e
(eg. echo -e '\033[1;34m'"${domain}"'\033[0m'
)... some shells don't use \e
and in such a case you'll generally have to use an alternative means of escaping characters.
If you run a script with sh script.sh
, you're explicitly using sh
as the shell rather than the one in the shebang line. That's bad news if sh
isn't a link to bash
. A plain sh
shell may not support echo -e
.
Type ./script.sh
to use the interpreter in the shebang line.
sh
if it uses bash
-specific features.
#!/bin/bash
at the top../script.sh
orsh script.sh
? Don't do the latter.