Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

\n in PS1 works fine, but when you try to type a command which takes more than one line, you type second line over the first and when you want to edit the part of such command that normally should be on the line above, the cursor goes at the line above it. Is there any cure for it, or bourne shell just wasn’t born for PS1 with newlines?

$ bash --version
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ bind -v
set bind-tty-special-chars on
set blink-matching-paren on
set byte-oriented off
set completion-ignore-case off
set completion-map-case off
set convert-meta off
set disable-completion off
set echo-control-characters on
set enable-keypad off
set enable-meta-key on
set expand-tilde off
set history-preserve-point off
set horizontal-scroll-mode off
set input-meta on
set mark-directories on
set mark-modified-lines off
set mark-symlinked-directories on
set match-hidden-files on
set menu-complete-display-prefix off
set meta-flag on
set output-meta on
set page-completions on
set prefer-visible-bell on
set print-completions-horizontally off
set revert-all-at-newline off
set show-all-if-ambiguous off
set show-all-if-unmodified off
set skip-completed-text off
set visible-stats off
set bell-style audible
set comment-begin #
set completion-display-width -1
set completion-prefix-display-length 0
set completion-query-items 100
set editing-mode emacs
set history-size 500
set keymap emacs

The modified prompt:

PS1="\[\033[01;34m\]\w\n\
\[\033[01;37m\]\]\
\`if [ \u != $LOGIN_NAME ]; then
    echo -n '\u'
fi\`\
\[\033[01;32m\]\
@\
\`if [ '\h' = '$MY_MACHINE' ]; then
    echo -n 'home'
else 
    echo -n '\h'
fi\`\
 \$ \[\033[00m\] "
share|improve this question
    
powershell_ise ... Shift+Enter ? –  STTR Feb 14 '13 at 12:14
1  
Bash 4.2.24 (on Ubuntu 12.04) works well with a multiline PS1. Can you post the output of bash --version and bind -v? –  jaume Feb 14 '13 at 12:15
1  
@sttr I use native bash in native environment –  tijagi Feb 14 '13 at 12:38
1  
Have you considered moving most of this into $PROMPT_COMMAND? –  Daniel Beck Feb 14 '13 at 14:41
1  
The second line of your PS1 appears to have an extra \] at the end. –  chepner Feb 14 '13 at 15:06
show 9 more comments

1 Answer

up vote 2 down vote accepted

The prompt string contained an extra "]" that was affecting how it was displayed.

share|improve this answer
add comment

Your Answer

 
discard

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.