The UNIX and Linux Forums  

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 12:23 PM
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 03:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
How to get Find command work with a variable passing "*" value? unxuser Shell Programming and Scripting 5 08-16-2006 11:47 AM
Unix "at" / "Cron" Command New Problem...Need help Mohanraj UNIX for Dummies Questions & Answers 3 01-26-2006 08:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2008
pdtak pdtak is offline
Registered User
  
 

Join Date: Feb 2008
Location: Sacramento
Posts: 33
"BOLD" printing a variable in PS1 command

I would like to "BOLD" print the hostname in the following statement:

export PS1=$USER"@"$(hostname -s):'$PWD>'

Is there a special character I can put before and after the variable to make it bold or blinking?

Thanks.
  #2 (permalink)  
Old 03-17-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 167

Code:
export PS1='\u@\033[1m`hostname`\033[0m:\w> '
or
export PS1='\u@\033[1m\h\033[0m:\w> '

//Jadu
  #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..
  #4 (permalink)  
Old 03-17-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
Hi.

Probably more than you'll ever want to know:
HOWTO: Change your Shell Prompt
Quote:
... This article will show you how to customize you prompts for the 6 most common shells. They are Bourne, Korn, BASH, Z, TC,and C. ...
cheers, drl
  #5 (permalink)  
Old 03-17-2008
pdtak pdtak is offline
Registered User
  
 

Join Date: Feb 2008
Location: Sacramento
Posts: 33
it worked, thanks!

tput method worked for me, thank you all for your generous input.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0