git配置——全局返回“语法错误接近意外令牌”)“错误”

时间:2021-01-13 19:11:26

When I try:

当我尝试:

$ git config --global user.name "Me"

it returns me this error:

它返回给我这个错误:

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

I'm running Git 2.6.3 on Windows 7 at C:\opt\git-2.6.3 and my .gitconfig was - at first - empty.

我在Windows 7上运行Git 2.6.3, C:\opt\ Git -2.6.3,而我的Git . config一开始是空的。

But, beside this error, it was filled with:

但是,除了这个错误之外,它还充满了:

[user]
name = Me

and, for each command that I type, the Prompt returns me the same error...

而且,对于我输入的每个命令,提示符都会返回相同的错误……

How can I fix this?

我该怎么解决这个问题呢?

With gratitude,

与感恩,

2 个解决方案

#1


2  

This is an issue with git bash interpreter.

这是git bash解释器的一个问题。

I have bisected the definition of PS1 in my .profile, and found that the problem appears if there were \n somewhere AFTER $(blablabla). Even "blablabla" is absolutely innocent, like echo helloworld.

我在我的.profile中对PS1的定义进行了分割,发现如果$(blablabla)之后的某个地方出现了\n,就会出现问题。甚至“blablabla”也绝对是无辜的,就像echo helloworld。

My solution was to emit the linefeed using another function:

我的解决方案是使用另一个函数发出linefeed:

function echonewline() {
  echo -e "\n "
  # last line must be non-empty - I emit a whitespace
}

PS1=\n...all...stuff...$(__git_ps1)...colors...$(echonewline) $
# newlines before first function call are welcome.

Looks weird, but it works.

看起来很奇怪,但确实有效。

Git bash v. 2.8.2 for Windows.

Windows的Git bash v. 2.8.2。

#2


2  

I also traced it to the \n following $(__git_ps1)

我还跟踪它到\n以下的$(__git_ps1)

Simplifying the PS1 prompt:

简化PS1提示:

This works:

如此:

PS1='$(__git_ps1)'

This does not; it gives the syntax error message:

这并不;它给出语法错误消息:

PS1='$(__git_ps1)\n'

However, giving the \n in ASCII does work:

但是,在ASCII中提供\n是可行的:

PS1='$(__git_ps1)\012'

Interestingly, after the \012 you can use \n again:

有趣的是,在\012之后,你可以再次使用\n:

PS1='$(__git_ps1)\012\n'

Note: I found additional errors in my PS1; not sure if they were there before, something odd happened when I updated git, or maybe (probably!) from my messing around in the distant past...

注意:我在PS1中发现了其他错误;不确定他们以前是否在那里,当我更新git时发生了一些奇怪的事情,或者(很可能!)

My PS1 (after updating git earlier today) was:

我的PS1(在今天早些时候更新git之后)是:

PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[33m\]\w \[\033[1m\]\[\033[31m\]$(__git_ps1)\[\033[0m\]\n$ '

This gives the syntax error, but also that first escape sequence is wrong:

这就产生了语法错误,但是第一个转义序列是错误的:

wrong!   PS1='\[\033]0;$MSYSTEM ...
right!   PS1='\[\033[0;m$MSYSTEM ...

the bracket after \033 was backwards and the 'm' was missing...

\033后面的括号是反的,m也不见了……

My corrected PS1 is now:

我修正的PS1现在是:

PS1='\[\033[0;m$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[33m\]\w \[\033[1m\]\[\033[31m\]$(__git_ps1)\[\033[0m\]\012$ '

this gives my prompt as:

我的提示是:

MINGW64:/c/Users/aweiner       <-white
aweiner@ajw-sony ~             <- green, dir in yellow, git branch name in red
$

(and yes, it's way verbose, so I'll probably mess with it some more...)

(是的,它太啰嗦了,所以我可能会把它弄得更乱……)

#1


2  

This is an issue with git bash interpreter.

这是git bash解释器的一个问题。

I have bisected the definition of PS1 in my .profile, and found that the problem appears if there were \n somewhere AFTER $(blablabla). Even "blablabla" is absolutely innocent, like echo helloworld.

我在我的.profile中对PS1的定义进行了分割,发现如果$(blablabla)之后的某个地方出现了\n,就会出现问题。甚至“blablabla”也绝对是无辜的,就像echo helloworld。

My solution was to emit the linefeed using another function:

我的解决方案是使用另一个函数发出linefeed:

function echonewline() {
  echo -e "\n "
  # last line must be non-empty - I emit a whitespace
}

PS1=\n...all...stuff...$(__git_ps1)...colors...$(echonewline) $
# newlines before first function call are welcome.

Looks weird, but it works.

看起来很奇怪,但确实有效。

Git bash v. 2.8.2 for Windows.

Windows的Git bash v. 2.8.2。

#2


2  

I also traced it to the \n following $(__git_ps1)

我还跟踪它到\n以下的$(__git_ps1)

Simplifying the PS1 prompt:

简化PS1提示:

This works:

如此:

PS1='$(__git_ps1)'

This does not; it gives the syntax error message:

这并不;它给出语法错误消息:

PS1='$(__git_ps1)\n'

However, giving the \n in ASCII does work:

但是,在ASCII中提供\n是可行的:

PS1='$(__git_ps1)\012'

Interestingly, after the \012 you can use \n again:

有趣的是,在\012之后,你可以再次使用\n:

PS1='$(__git_ps1)\012\n'

Note: I found additional errors in my PS1; not sure if they were there before, something odd happened when I updated git, or maybe (probably!) from my messing around in the distant past...

注意:我在PS1中发现了其他错误;不确定他们以前是否在那里,当我更新git时发生了一些奇怪的事情,或者(很可能!)

My PS1 (after updating git earlier today) was:

我的PS1(在今天早些时候更新git之后)是:

PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[33m\]\w \[\033[1m\]\[\033[31m\]$(__git_ps1)\[\033[0m\]\n$ '

This gives the syntax error, but also that first escape sequence is wrong:

这就产生了语法错误,但是第一个转义序列是错误的:

wrong!   PS1='\[\033]0;$MSYSTEM ...
right!   PS1='\[\033[0;m$MSYSTEM ...

the bracket after \033 was backwards and the 'm' was missing...

\033后面的括号是反的,m也不见了……

My corrected PS1 is now:

我修正的PS1现在是:

PS1='\[\033[0;m$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[33m\]\w \[\033[1m\]\[\033[31m\]$(__git_ps1)\[\033[0m\]\012$ '

this gives my prompt as:

我的提示是:

MINGW64:/c/Users/aweiner       <-white
aweiner@ajw-sony ~             <- green, dir in yellow, git branch name in red
$

(and yes, it's way verbose, so I'll probably mess with it some more...)

(是的,它太啰嗦了,所以我可能会把它弄得更乱……)