-e
-e
enables the interpretation of backslash characters.
The following line prints Hello, world!
echo -e "\x48\x65\x6c\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21"
echo -e "\e[1;31mTHIS TEXT IS RED\e[0m"
Colored output
#!/bin/bash
echo
echo ANSI escape sequences
echo ---------------------
NOCOL_="\e[0m"
BOLD__="\e[1m"
UNDERL="\e[4m"
REVERS="\e[4m" # Swap foreground and background colors (sometimes underline?)
BLACK_="\e[30m"
RED___="\e[31m"
GREEN_="\e[32m"
YELLOW="\e[33m"
BLUE__="\e[34m"
PINK__="\e[35m"
CYAN__="\e[36m"
WHITE_="\e[37m"
function print_colored {
printf $1
printf " %-8s" $2
printf $BOLD__
echo -n $2
printf $NOCOL_
echo
}
print_colored $BLACK_ Black
print_colored $RED___ Red
print_colored $GREEN_ Green
print_colored $YELLOW Yellow
print_colored $BLUE__ Blue
print_colored $PINK__ Pink
print_colored $CYAN__ Cyan
print_colored $WHITE_ White
print_colored $UNDERL Underln
print_colored $REVERS Revers