Um pequeno script para obter os códigos enigmáticos ;)
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
T='gYw' # The test text
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs 3[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS 3[$FG3[$BG $T 3[0m";
done
echo;
done
echo
Ocódigoéfácildelernatabelaquegerouoscriptanterior.
\e[1;37m\e[44m
\e[1;37m
-primeiroplano\e[44m
-Planodefundo
Algunsexemplos
Primeiroplanobranco
TOA="\e[0m" # No Color whiteForeground="\e[1;37m" echo -e "${whiteForeground}foo${TOA}"
-
Branco em azul
TOA="\e[0m" # No Color whiteOnBlue="\e[1;37m\e[44m" echo -e "${whiteOnBlue}foo${TOA}"
E um script bash de amostra:
red="\e[0;31m"
green="\e[0;32m"
yellow="\e[0;33m"
blue="\e[0;34m"
TOA="\e[0m" # No Color
if [[ $cfg_log_level == "" ]]; then
cfg_log_level=4
fi
function logError () {
if [[ $cfg_log_level == "1" ]] || [[ $cfg_log_level == "2" ]] || [[ $cfg_log_level == "3" ]] || [[ $cfg_log_level == "4" ]]; then
echo -e "${red}$1${TOA}" 1>&2
fi
}
function logWarn () {
if [[ $cfg_log_level == "2" ]] || [[ $cfg_log_level == "3" ]] || [[ $cfg_log_level == "4" ]]; then
echo -e "${yellow}$1${TOA}" 1>&2
fi
}
function logInfo () {
if [[ $cfg_log_level == "3" ]] || [[ $cfg_log_level == "4" ]]; then
echo -e "${green}$1${TOA}" 1>&2
fi
}
function logDebug () {
if [[ $cfg_log_level == "4" ]]; then
echo -e "${blue}$1${TOA}" 1>&2
fi
}