If you want a quick easy way to add some colors to your own shell scripts: export STDOUT_COLOR_START='[34m' export STDOUT_COLOR_STOP='[0m' export STDERR_COLOR_START='[31m' export STDERR_COLOR_STOP='[0m' In your shell script: print_stdout() { printf %s%s%s\\n "${STDOUT_COLOR_START:-}" "$*" "${STDOUT_COLOR_STOP:-}" } print_stderr() { >&2 printf %s%s%s\\n "${STDERR_COLOR_START:-}" "$*" "${STDERR_COLOR_STOP:-}" } Sou…
That seems needlessly cumbersome, why not declare STDOUT_COLOR='\e[34m' declare STDERR_COLOR='\e[31m' declare COLOR_STOP='\e[0m' print_stdout() { echo -e "${STDOUT_COLOR}${*}${COLOR_STOP}" &> /dev/stdout } print_stderrr() { echo -e "${STDERR_COLOR}${*}${COLOR_STOP}" &> /dev/stderr } Like why are you exporting? Do you really need those in your environment? And those print statements aren't going to work by default.
For shell syntax, I aim for POSIX because for anything more advanced I switch from shell to a more powerful programming language.
Currently POSIX doesn't have the 'declare' statement, nor the '\e' syntax consistently, nor the 'echo -e' syntax consistently.
As for exporting, I do it because I have many quick scripts that I run often, and I prefer to switch the colors in one place such as in the evening from light mode to dark mode.
When you say the print statements aren't going to work by default, can you say more about this? Anything you can explain or point me to about this will be a big help. Thanks!