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.

I have Fedora 20, and I would like to adapt the bash prompt to make it even more useful to me. At present my PS1 prompt is set by these lines in my ~/.bash_profile file:

 LP=" Last prompt at: "
 PS1="\[\033[s\033[0;0H\033[0;47m\033[K\033[1;34m[\$LP\]t\033[0m\033[u[<\u@\h \W>]\$ "

Which gives me a nice line at the top of the screen, with a grey bar (which does not show in this copy) and the time of the last prompt, thus:

[ Last prompt at: ]09:22:46
[<Harry@localhost ~>]$ 

Without the echo, when a terminal screen is opened, the prompt obscures the message on the top line. What the echo does is to echo its argument, so that when .bashrc. is run as a new terminal is opened, with no argument it nicely goes to a new line, leaving the top line alone. Subsequent prompts do not run .bashrc so the echo to a new line does not happen.

My question here concerns the "[ ]" brackets in the prompt round the Last prompt at: string. Please, how can I avoid these brackets appearing in the message displayed?

In response to @guido's answer. I had already tried just removing the square brackets, but then I lost the string completely. I note here that you have added a space after the LP, and that does indeed give me what I want, but I don't understand why the space is necessary: please could you add to your answer to explain that?

share|improve this question
You quoted too much. –  mikeserv May 27 '14 at 9:56
@mikeserv could you please explain that suggestion? –  Harry Weston May 27 '14 at 22:23
But @guido already did... –  mikeserv May 27 '14 at 22:31
There are two kinds of explanation: those that allow the experts to mod wisely, and those that make things clear to the naive enquirer. I was after the second one. –  Harry Weston May 28 '14 at 9:42
Well, escape sequences are generally denoted by opening and closing [ square brackets ] - in combination with other characters - and these serve similarly to "quotes. It's a long string - my eyes are crossing - but you had at least one too many. Sorry for before. –  mikeserv May 28 '14 at 12:43

2 Answers 2

up vote 5 down vote accepted

Just remove the square brackets from your PS1 (also there was a typo around \t):

LP=" Last prompt at: "
PS1="\[\033[s\033[0;0H\033[0;47m\033[K\033[1;34m\$LP \t\033[0m\033[u\][<\u@\h \W>]\$ "
share|improve this answer

Guido's already answered your specific question, but just a note:

In addition, you could also set your scrolling region to be from the second line, so that scrolling doesn't erase that line.

PS1="\[\e[s\e[2;0r\e[H\e[0;47m\e[K\e[1;34m$LP\t\e[0m\e[u\]<\u@\h \W>\$ "

(though personally, I wouldn't to this kind of thing at the shell level, but for instance using screen and its hardstatus feature)

share|improve this answer

Your Answer


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.