You can use watch -c or –color option to interpret ANSI color and style sequences.
Example:
Create and execute a script that inserts 1 line in different colors
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
## create a script to insert 1 item of every color combination cat << 'EOF' > myscript.sh #!/bin/bash > myfile for fgbg in 38 48 ; do # Foreground / Background for color in {0..255} ; do # Colors # Display the color printf "\e[${fgbg};5;%sm %3s \e[0m" $color $color >> myfile echo >> myfile sleep 2 done echo >> myfile done EOF ## execute the script in the background chmod +x myscript.sh ./myscript.sh & |
watch -c or –color option example
1 2 3 4 5 6 7 |
## watch -c or --color option example watch tail myfile ## does not interpret ANSI color watch -c tail myfile ## interpret ANSI color pkill -f "myscript.sh" ## kill myscript.sh unset -f myfun rm my* |