\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:

\`if [ \u != $LOGIN_NAME ]; then
    echo -n '\u'
\`if [ '\h' = '$MY_MACHINE' ]; then
    echo -n 'home'
    echo -n '\h'
 \$ \[\033[00m\] "
  • 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

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

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.