Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I type below command in the shell I get the OUTPUT in green color.

Command

echo "\033[32mCONNECTING TO abpwrk\033[m";

Output(in green color)

CONNECTING TO abpwrk

But if I use the same statement in a small one line script and execute it.Then I get the output(in white color).

\033[32mCONNECTING TO abpwrk\033[m

What am I missing in the script.Do I need to define some extra parameters to initiate colors ? I am using k-shell.

share|improve this question
2  
Post your script. I am sure that one is not interpreted by ksh. Try echo -e "\033[32mCONNECTING TO abpwrk\033[m" – if that works, your script is probably interpreted by bash. –  manatwork Oct 26 '12 at 12:21
    
It worked.Thanks –  g4ur4v Oct 26 '12 at 12:33
add comment

1 Answer

You probably are using different shells with different echo implementations. At least in bash's implementation of echo, interpretation of escape sequences is not enabled by default (you have to enable it with the -e switch).

In any case, printf is generally more conformant between environments. Try using the following instead:

_host=abpwrk ; printf '\033[32mCONNECTING TO %s\033[m\n' "$_host"
share|improve this answer
    
What about tput setaf and tput setab (both followed by a digit)? @g4ur4v: Check out this question. –  Emanuel Berg Oct 27 '12 at 0:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.