In bash (or in zsh or any other shell), you can use the terminal escape sequences directly (apart from a few exotic ones, all terminals follow xterm's lead these days). CSI is ESC [, written $'\e[' in bash. The escape sequence to change attributes is CSI Ps m. Echo $'\e...
In the first line you define $foo with the value '10' and $x with the value 'foo'. Now define $y, which consists of the string '$foo'. The dollar sign must be escaped with '$'. To check the result, echo $y.