The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 03-17-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
That's pretty much the copy+paste answer, but it's in bash syntax, which may or may not work for you.

In general, ANSI codes starting with esc [ and ending with m after some numbers work well, but they're not portable to all terminals. A (slightly) more portable solution would be to use tput

Code:
PS1=$USER"@"$(tput bold)$(hostname -s)$(tput sgr0):'$PWD>'
See the tput manual page for more information.

Perhaps you will find that the codes output by tput are exactly equivalent to the hard-coded escape codes given above. In theory, tput should be portable to terminals which do not speak ANSI, but I don't know of a real-world situation where this would make an enormous difference.

(The code \033 is octal for the escape character.)

Last edited by era; 03-17-2008 at 03:00 PM..