0

我正在使用 Markdown 编辑模式在 GitHub 上编辑 Wiki 页面,并尝试从 shell 脚本中插入一段代码,如下所示:

```
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
```

但是,该块最终看起来像这样:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[SAME-43-CHAR-SEQUENCE[01;32m\]\u@\h\[SAME-43-CHAR-SEQUENCE[00m\]:\[SAME-43-CHAR-SEQUENCE[01;34m\]\w\[SAME-43-CHAR-SEQUENCE[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

所以它看起来像是将 char 序列解释\033为某种SAME-43-CHAR-SEQUENCE看起来像某种 UUID 的代码。我怎样才能避免这种情况?谢谢

4

1 回答 1

0

用另一个斜线转义斜线似乎可行。

所以,\033改为\\033

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\\033[01;32m\]\u@\h\[\\033[00m\]:\[\\033[01;34m\]\w\[\\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
于 2012-11-07T17:56:17.237 回答