In a terminal emulator like xterm my prompt looks like this:

[august@macmini ~]$

but in a virtual console the string ;linux is prepended to the prompt to make it look like this:

;linux[august@macmini ~]$

Does anyone know where the "linux" string may come from?

  • 1
    show us your $PS1 (and $PROMPT_COMMAND if you have one) – glenn jackman May 5 '13 at 16:38
  • glenn jackman: Thanks for the hint. Apparently the prompt command is the source of the problem; when it is set to set the window title with echo -ne "\033]0;$TERM\007" it behaves strangely in console mode (where there is no window). – August Karlstrom May 7 '13 at 8:03
  • I've often seen in a .bashrc case $TERM in xterm*|rxvt*) PS1=...includes.window.title... ;; *) PS1=...no.title... ;; esac – glenn jackman May 7 '13 at 10:51

It turns out that things go wrong when a command to set the window title is executed in a virtual console (where there is no window). Changing

PROMPT_COMMAND='printf "\e]0;%s\a" "$TERM"'


if [[ $TERM = xterm* ]]; then
    PROMPT_COMMAND='printf "\e]0;%s\a" "$TERM"'

solves the problem.

  • 1
    Since it's an xterm thing, I'd check if TERM is xterm instead. if [[ $TERM = xterm* ]]; then PROMPT_COMMAND='printf "\e]0;%s\a" "xterm title here"'; fi – geirha May 7 '13 at 11:46
  • geirha: OK, I didn't know it was xterm specific. I have updated my answer. Thanks! – August Karlstrom May 7 '13 at 13:49

Just for fun, here's how I set my prompt:

# inspiration: http://www.stumbleupon.com/su/2LpQMi 
user_host_path="${debian_chroot:+($debian_chroot) }"'\u@\h: \w'
[[ $TERM == xterm* || $TERM == rxvt* ]] && first_part="${xterm_title}"
last_part='\! \$ '
PROMPT_COMMAND="((\$? != 0)) && PS1='${first_part}${color_bold}[\$?]${color_reset} ${last_part}' || PS1='${first_part}${last_part}'"
unset user_host_path xterm_title color_bold color_reset first_part last_part

Looks like this:

glennj@homebase: ~
200 $ (exit 42)

glennj@homebase: ~
[42] 201 $ cd /tmp

glennj@homebase: /tmp
202 $ 

I wasn't crazy about the solution provided here since I use the same TERM for Ubuntu virtual terminals as other terminals (screen-256color). Thus, I took a quick look at what other environment variables could be useful for this purpose.

My conclusion was to use the XDG_VTNR (XDG virtual terminal number?) variable. Since Ubuntu uses VT#7 for the desktop environment, a simple check for whether this variable is greater than or equal to 7 does the trick.

I have bash function that builds my prompt anyway, so I just surrounded the title escape sequence addition with a check against the XDG_VTNR variable.

For example, note the bolded portion below:

# Use new test (i.e. [[ ]]) so as not to fail if XDG_VTNR does not exist
if [[ $XDG_VTNR -ge 7 ]]; then
  # Add the window title escape sequence to the prompt
  # Don't add the window title escape sequence to the prompt

Just wanted to add this note in case it can be useful for anyone else.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.