PS1 中的 \n 工作正常,但是当您尝试输入一个多行命令时,您会在第一行上输入第二行,并且当您想要编辑该命令中通常应该在上面一行的部分时,光标会移动到其上一行。有没有什么办法可以解决这个问题,或者 Bourne Shell 不是为带有换行符的 PS1 而生的?
$ 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
修改后的提示:
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\] "
答案1
提示字符串包含额外的“]”,这影响了它的显示方式。