简体   繁体   English

为什么此代码在 Linux 上的 bash 中有效,而在 Windows 上的 git-bash 中无效

[英]Why does this code work in bash on Linux, but not in git-bash on Windows

I have set up my bash prompt like so:我已经像这样设置了我的 bash 提示:

vcs(){
  if [ $PROMPT_VCS -eq "1" ] && [ $have_vcprompt -eq "1" ]; then
    echo -en "$(vcprompt -f "on ${EMM}%n${EMW}:%b${G}%m${R}%u${NONE}")"
  fi
}

bash_prompt() {
  case $TERM in
    xterm*|rxvt*)
      local TITLEBAR='\[\033]0;${SHORT_HOST} ${NEW_PWD}\007\]'
      ;;
    *)
    local TITLEBAR=""
    ;;
  esac

  local UC=$EMG
  [ $UID -eq 0 ] && UC=$EMR

  local ARROW_COLOR=$EMR
  [ $? -eq 0 ] && ARROW_COLOR=$EMG

  PS1="\[${TITLEBAR}\
${UC}\u \
${NONE}at ${EMY}\h \
${NONE}in ${EMB}\${NEW_PWD} \
${NONE}\$(vcs) \
${K} \
\[${NONE}\]\n\[${ARROW_COLOR}\]\$ \[${NONE}\]"

}

This works perfectly on my laptop running Debian, but on Windows, using git-bash, I get the following error:这在我运行 Debian 的笔记本电脑上完美运行,但在 Windows 上,使用 git-bash,我收到以下错误:

bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `vcs)'

The VC info consequently does not appear in the prompt. VC 信息因此不会出现在提示中。 I don't understand why git-bash has a problem with that closing bracket..我不明白为什么 git-bash 的右括号有问题..

Thanks to Gerrit's comment, the answer was found here .感谢 Gerrit 的评论,在这里找到了答案。 The functioning version (including newline) looks like this:功能版本(包括换行符)如下所示:

  PS1="\[${TITLEBAR}\
${UC}\u \
${NONE}at ${EMY}\h \
${NONE}in ${EMB}\${NEW_PWD} \
${NONE}\$(vcs) \
${K} \
\[${NONE}\]\[${ARROW_COLOR}\]"$'\n$ '"\[${NONE}\]"

If someone could explain what causes this problem that would be even better.如果有人能解释导致这个问题的原因,那就更好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM