在設置命令行提示符的字體顏色之後,輸入超過一行的命令時會覆蓋當前行內容,不能自動換行。問題原因是命令提示符中有控制字符(如字體顏色),它需要使用 \[
和\]
包圍。
以下摘抄自bash的manpage中PROMPTING一節
\[ begin a sequence of non-printing characters, which
could be used to embed a terminal control sequence
into the prompt
\] end a sequence of non-printing characters
參考文章: