Color on echo output does not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Color on echo output does not work
# 1  
Old 09-29-2010
Color on echo output does not work

Hi,
When I run:
Code:
echo "\033[1;31mhi\033[m"

I see hi in color, but if I run this color is not shown, why?
Code:
(echo "\033[1;31mhi\033[m")|more

Thanks
Israel.

---------- Post updated at 05:17 AM ---------- Previous update was at 04:43 AM ----------

DONE!!

I had to run more -v.

Thanks
# 2  
Old 09-29-2010
Remember the usage of Linux and/or ANSI color escape sequences is inherently unportable. You might want to investigate terminfo and tput to do this portably.
# 3  
Old 09-29-2010
Quote:
Originally Posted by cjcox
Remember the usage of Linux and/or ANSI color escape sequences is inherently unportable. You might want to investigate terminfo and tput to do this portably.
There are very few non-ANSI terminals left in this world. "Linux" escape sequences are mostly just ANSI ones. Where I still see huge disagreement between terminals is what key means which...
# 4  
Old 09-29-2010
So.. what you're saying is that your solution isn't portable, but you BELIEVE that the world will eventually agree with your assumption about what a terminal is? Right? I stand by the advice I gave... it's worth your while (it's really not all that bad to learn how to do things right).
# 5  
Old 09-30-2010
Quote:
Originally Posted by cjcox
So.. what you're saying is that your solution isn't portable, but you BELIEVE that the world will eventually agree with your assumption about what a terminal is? Right?
No. Usually, simple reading is an exercise left to the reader, but I'll help you along a little bit by breaking it into bullet points.
  • You're using "linux terminal" pejoratively. Linux terminals are ANSI. Sometimes with extensions, but the extensions are rarely used.
  • Color isn't one of these extensions, it's a basic ANSI feature. There's no special "Linux" color escape sequence which doesn't work in the rest of the world.
  • There are very few non-ANSI terminals left in the UNIX world. Portable is as portable does.

...we're not talking about an essential feature here, anyway. If someone wants to use this program over an ancient teletype, it's a trivial change.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Change text color from echo command?

I have a bash script that starts and stops a game among other things through in.fifo and out.fifo In game the text comes out gray . Kinda hard to see in game window . I would like to change it to purple and maybe capitalize it. #!/bin/bash #nwservctl.sh cd... (5 Replies)
Discussion started by: 222222quick
5 Replies

2. Shell Programming and Scripting

Color prompt with file numbers does not work anymore

I have used this color prompt on my servers for long time, in file ~\.bashrc Black="\" Dark="\" Blue="\" LBlue="\" Green="\" LGreen="\" Cyan="\" LCyan="\" Red="\" LRed="\" Purple="\" LPurple="\" Brown="\" Yellow="\" LGray="\" White="\" Reset="\" PS1="$Yellow\u@\h $LBlue\w... (4 Replies)
Discussion started by: Jotne
4 Replies

3. UNIX for Dummies Questions & Answers

How to change color when doing echo in tcsh?

Is it possible to change the color when doing an echo? Example, having the following command print in dark blue. echo "Hello" ---------- Post updated at 11:50 AM ---------- Previous update was at 10:25 AM ---------- Just figured out how to do it (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

echo doesn't work right

Hi,when I run my first shell script,I got something that doesn't work right. I wrote this code in the script. echo -e "Hello,World\a\n"But the screen print like this: -e Hello,World The "-e" wasn't supposed to be printed out. Can anyone help me out?:wall: Many thanks!:) (25 Replies)
Discussion started by: Demon
25 Replies

5. Shell Programming and Scripting

give some color to a word on echo output

Hi Supposed this text output: How can I show $HOSTNAME in other color than blank? :-) KSH on AIX (4 Replies)
Discussion started by: iga3725
4 Replies

6. UNIX for Dummies Questions & Answers

'echo dir_path | xargs cd' does not work?

Hi: how come this command does not work? the error message is: xargs: cd: No such file or directory yet, in the same time, 'echo dir_path | xargs ls' works. Does it work in bash? We use csh. Thanks. NB Phil (7 Replies)
Discussion started by: phil518
7 Replies

7. Shell Programming and Scripting

.bashrc/PS1 command color different color to command output

I have been configuring my .bashrc PS1 to be displayed with some nice colors and in a format that I like, however there is one thing that I cannot figure out (or know if it's even possible). my PS1 line is as follows: export PS1='\\u\@\\h\:\\w\n\\$ \'This makes the command and command output... (0 Replies)
Discussion started by: jelloir
0 Replies

8. Shell Programming and Scripting

ksh - how to echo something in color and bold

Hi all, I was to echo Hi in Red and Bold ; and echo There is in Green and bold I got bold to working using tput bold but i am having hard time getting the color. Any help is appreciated, jak (4 Replies)
Discussion started by: jakSun8
4 Replies
Login or Register to Ask a Question