How to write a text file with color
Have you tried less -R file.txt
? That should show you the colour (works for me at least).
If you want colour coding which is supported by non-shell applications your best bet is probably to output HTML, for example:
printf '<code style="color: %s;">%s</code>' "green" "ffmpeg -t $DURACION -f x11grab -s $RESOLUCION -r ${FPS[j]} -b:v $BR -i :0.0 -y $NOMBRE" >> file.html
Use printf
instead of echo -e
:
printf
portably supports interpreting \
-based escape sequences, whereas echo -e
isn't supported on all platforms, notably not on macOS.
printf "\e[1;32mffmpeg -t $DURACION -f x11grab -s $RESOLUCION -r ${FPS[j]}\
-b:v $BR -i :0.0 -y $NOMBRE\e[0m\n" >> file.txt
Note the trailing \n
to print a newline after the string, because printf
- unlike echo
- doesn't automatically add one.