简体   繁体   English

Git 使用与 bash 不同的 shell 别名

[英]Git using for aliases different shell than bash

I am learning git for some time, recently I have been using aliases.我学习git有一段时间了,最近我一直在使用别名。 Everything was working, until last time.一切正常,直到最后一次。 My example alias stopped working ( git simple-commit works fine )我的示例别名停止工作(git simple-commit 工作正常)

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

I am getting fatal in terminal我在终端变得致命

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

It looks like git not using bash shell.看起来 git 没有使用 bash shell。 Any idea what is going on?知道发生了什么事吗?

I just tested a simplified version of that alias:我刚刚测试了该别名的简化版本:

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

And git aa does give the expected result:并且git aa确实给出了预期的结果:

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

To be sure, assuming Git for Windows, test your alias in a CMD session with a simplified PATH :可以肯定的是,假设 Git for Windows,使用简化的PATHCMD会话中测试您的别名:

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%

You can also use a number for i ( i=1 instead of "1" ) and use other syntax to increment that variable (like i=$((i+1)) )您还可以为i使用数字( i=1而不是"1" )并使用其他语法来增加该变量(如i=$((i+1))

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

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