I want to change the colour of the whole line of echo
that I get. How do I? I am using zsh shell. The terminal I am using is iTerm. Please help. Thanks. I am on a mac with macOS Sierra 10.12.5. I've written a bash script just which is echo "World is green"
. Please do help.
Answer
Use
echo "$(tput setaf 2)World is green$(tput sgr0)"
to change the foreground color to green (2) and to reset it later (you can experiment with other numbers).
Just to clarify things, the terminal is who can change the display colors and has nothing to do with bash or zsh, which in this case is only sending the right sequence, as you can see running (in my Linux terminal)
echo "$(tput setaf 2)World is green$(tput sgr0)" | xxd
00000000: 1b5b 3332 6d57 6f72 6c64 2069 7320 6772 .[32mWorld is gr
00000010: 6565 6e1b 2842 1b5b 6d0a een.(B.[m.
No comments:
Post a Comment