Monday, May 18, 2015

PuTTY - Script Output in Different Color

No comments:
I was writing a shell script with rather verbose output, and was getting confused with which output was from which invocation of the command. I started clearing the screen between commands, but sometimes forgot. There's got to be a better way....

How about if I changed the color of the output? This article turned me onto the basic method, which had to be fine tuned due to my use of the zenburn color theme. Also, I found that, for some reasons, the color macros that work on the command line were not working in the scripts. Doesn't matter... I can now start and end scripts with commands to change color, and get the output in a different color....

So, a shell script (myscript.sh) like this...

#!/bin/bash
echo -e "\e[0;32m----------------------------------------------------"
echo "My Script Output"
echo -e "----------------------------------------------------\e[0m"

Will output the following (assuming you are using the zenburn color theme)....
[root@local ~] ~/myscript.sh
----------------------------------------------------
My Script Output
----------------------------------------------------
[root@local ~]