Thoughtful adventures in the operating system

Color text output on bash scripts

Users who have been using Linux for awhile often learn that creating a basic script is a good way to run multiple, often-repeated commands. Adding a little color to scripts can additionally provide nice feedback. This can be done in a fairly straight-forward way by using the tput command.

A common way of doing this is to define the colors that tput can produce by putting them at the beginning of the bash script:

Apple uses BSD developed tools that are basically forks of earlier versions of Linux tools. Generally, because GNU/Linux tools were used more they got better developed, so the transition between many tools with the same name in BSD’s and Linux’s can be different.

On a 256-color terminal like xterm, PuTTY, or Terminal.app (make sure to set the right config options like `export TERM=xterm-256color`), you can replace the 7 in `for i in $(seq 1 7); do` in the `tputcolors` script with 255 to get all the possible colors. It makes for a much more colorful time!

Welcome

Here is a gathering place to share common bits of Linux knowledge. Learning with the operating system is a hobby for me. I enjoy getting along with people and being part of something everyone can contribute to. Comments, tips all liked.

If desired you can learn more about me or view the number of scripts I've wrote.