In bash, you need to use color escape sequences with echo -e
random_colors.sh
#!/bin/bash
TXT='the quick brown fox jumped over the lazy dog.'
WORDS=( $TXT )
for WORD in "${WORDS[@]}"; do
let "i=$RANDOM % 256"
echo -en "e[38;5;${i}m$WORD e[0m";
done;
echo
Running this 10 times:
for i in `seq 1 10`; do bash random_colors.sh; done
Output
To get a particular palette, you will need to restrict the set of color numbers.
ANSI Escape Codes for Colors
Colors and Formatting
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…