\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\] "