"BOLD" printing a variable in PS1 command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "BOLD" printing a variable in PS1 command
# 1  
Old 03-17-2008
"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  
Old 03-17-2008
Code:
export PS1='\u@\033[1m`hostname`\033[0m:\w> '
or
export PS1='\u@\033[1m\h\033[0m:\w> '

//Jadu
# 3  
Old 03-17-2008
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 04:00 PM..
era
# 4  
Old 03-17-2008
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  
Old 03-17-2008
it worked, thanks!

tput method worked for me, thank you all for your generous input.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk variable into shell command "date -d": possible...?

Hello, there! I am trying to pass an awk variable into a shell command in order to collect the result into an awk variable; in Bash it does work, as in: v='2'; date -d "now + $v weeks" But in awk it does not, as in: v="2" "date -d 'now + v weeks'" | getline newdate close ("date -d 'now... (3 Replies)
Discussion started by: fbird3
3 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Solaris

Netra X1 LOM: Unable to change any variable via the "set" command

I'm posting here as it didn't seem quite right in the hardware section (as it's LOM commands). My apologies if I have that wrong though :) I've finally gotten round to configuring the LOM on my Netra X1, but I can't get it to change the hostname via the "set" command: lom>show hostname... (2 Replies)
Discussion started by: Smiling Dragon
2 Replies

4. Shell Programming and Scripting

Cat Command on File not printing "Blank" Lines?

Hello All, I have a bash script and in it at some point I call an Expect Script that does some stuff and saves its output in a ".txt" file. Example "/path/to/my/file/Expect_Output.txt" file: notice the 2nd line is empty in the file... Data for Host-1 (192.168.1.110) Checking the... (2 Replies)
Discussion started by: mrm5102
2 Replies

5. Shell Programming and Scripting

Variable interpolation in "print" of awk command

Hi, I have a snippet like below. Based on variable i, i wish to print 1,2,3,4,5th columns to Sample files. For each loop, one column from contetn and results will be pused to sample files. But i have a problem here i=1 while ; do `awk -F"\t" '{print $($i)}' $content > Sample_${i}_original`;... (4 Replies)
Discussion started by: forums123456
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Storing output of "time" command to a variable

Hi all, I am new to Linux/shell scripting having moderate knowledge. In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save... (9 Replies)
Discussion started by: happening_linux
9 Replies

8. Shell Programming and Scripting

Custom PS1 "anamoly"

Hello: Any bash PS1 gurus in the house? I have a custom 2-line prompt and it displays fine, but there is an occasional anomaly. The backspace key sometimes takes out the 2nd line. Here's the relevant ~/.bashrc code: MKF='This is my Kung-Fu' DOS='C:${PWD//\//\\\}>' PS1="\$MKF\n\\" ... (0 Replies)
Discussion started by: Habitual
0 Replies

9. Shell Programming and Scripting

How can I use a pipe operator in a variable: OPTION="| command"?

I have a string of commands I am piping some data through and I want to allow command line switches to select which commands are used. I want to do something like this: OPTION="| command3" command1 -a -b c.txt | command2 -d -e $OPTION >result.txt I want to do it that way because OPTION may be... (1 Reply)
Discussion started by: KenJackson
1 Replies

10. Shell Programming and Scripting

How to get Find command work with a variable passing "*" value?

Hi guy, I have a problem to pass a variable containing '*' value to FIND command. below is the script. It doesn't work by submit below command: rmf.sh name '*.txt' or rmf.sh name *.txt I've tried either optn="-name '$2'" or optn="-name $2"., and there is no luck. ### (script... (5 Replies)
Discussion started by: unxuser
5 Replies
Login or Register to Ask a Question