如何转义 PS1 环境变量中的感叹号?

Mor*_*n H 5 bash prompt quoting

即使我尝试用反斜杠转义它,它也会被历史编号替换。

Spa*_*sle 4

如果您只想在提示中使用感叹号,则无需转义它。

PS1='foobar!'   
Run Code Online (Sandbox Code Playgroud)

走着瞧吧。