Hi folks,
just a short question, please allow me to ask:
How can I get coloured text output in a shell script?
I am using:
echo "my text bla"
As far as I read and understood, this is not possible in every shell. I found
nothing in bash manual for example.
Debian is using "dash" and not "bash", if I am correct, and with using the
shebang line :!/bin/sh it is using dash, am I correct?
If I want coloured text, which shell do I have to use and what is the syntax
then within the shell script?
I searched the web, but could not find a clear answer to this.
Thanks for a short answer.
Best regards
Hans
"sh" is probably "/usr/bin/sh" ("$ command -v sh" or the (now-deprecated?) "which sh" will show you which "sh" is being called), which is probably a symlink to "dash" ("ls -lah <path>" will show that to you).
But not necessarily.
Perhaps one of the easiest ways to get color in a bash/dash/sh shell is to use ANSI Terminal Escape Sequences. Not 100% portable, but probably suitable for what you want.
Something like:
#!/bin/env sh
printf "\033[31m"
printf "Now we're printing in Red\n"
printf "\033[0m"
printf "Now we're printing in the system default color.\n"
--