Git 使用的别名 shell 不同于 bash

Git using for aliases different shell than bash

学习git有一段时间了,最​​近一直在用别名。一切正常,直到最后一次。我的示例别名停止工作(git simple-commit 工作正常)

simple-loop = "!simpleLoop() { NAME=; i="1"; while [ $i -le  ]; do git simple-commit $NAME$i; i=$[$i+1]; done; }; simpleLoop"

我在终端快死了

simpleLoop() { NAME=; i=1; while [ $i -le  ]; do git simple-commit $NAME$i; i=$[$i+1]; done; }; 
simpleLoop: 1: [: Illegal number: $[1+1]

看起来 git 没有使用 bash shell。 知道发生了什么事吗?

我刚刚测试了该别名的简化版本:

aa = "!simpleLoop() { i="1"; while [ $i -le "4" ]; do echo $i; i=$[$i+1]; done; }; simpleLoop"

git aa 确实给出了预期的结果:

D:\git\>git aa
1
2
3
4

可以肯定的是,假设 Git 对应 Windows,使用简化的 PATH:

CMD 会话中测试您的别名
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\cmd;%GH%\mingw64\bin;%PATH%

您还可以为 i 使用数字(i=1 而不是 "1")并使用 other syntax to increment that variable(如 i=$((i+1))