哪个shell用于git'!'别名?

时间:2016-09-12 04:02:02

标签: git

执行以git开头的别名时,!使用了哪个默认shell?

我怀疑它是/ bin / sh,因为在别名vs我的shell(read)中使用bash时,我会遇到不同的行为。

+ravi@boxy:~/.dotfiles(master*% u+2)$ grep 'test =' ~/.gitconfig    
        test = "!f() { read -n1 -p "Works?" r; } ; f "
+ravi@boxy:~/.dotfiles(master*% u+2)$ git test
f() { read -n1 -p Works? r; } ; f : 1: read: Illegal option -n
+ravi@boxy:~/.dotfiles(master*% u+2)[2]$ read -n1 -p "Works?" r; # Try it in current shell (bash)
Works?Y+ravi@boxy:~/.dotfiles(master*% u+2)$ # OK, that worked...
+ravi@boxy:~/.dotfiles(master*% u+2)$ grep 'sh =' ~/.gitconfig
        sh = "!f() { exec \"$@\"; }; f"
+ravi@boxy:~/.dotfiles(master*% u+2)$ git sh env | grep SHELL
SHELL=/bin/bash
+ravi@boxy:~/.dotfiles(master*% u+2)$ # WTF??????????
+ravi@boxy:~/.dotfiles(master*% u+2)$ type read
read is a shell builtin
+ravi@boxy:~/.dotfiles(master*% u+2)$ which read
+ravi@boxy:~/.dotfiles(master*% u+2)[1]$ # none, so why is the shell behaving differently?
+ravi@boxy:~/.dotfiles(master*% u+2)[1]$ git sh bash -c read -n1
Hmm, this is ok??
+ravi@boxy:~/.dotfiles(master*% u+2)$ # Yes, that worked.

如何设置在处理以!开头的别名时使用的shell?

1 个答案:

答案 0 :(得分:2)

As described here,你可以看到更多:

GIT_TRACE=1 git test

解决方法是创建一个名为git-xxx的shell脚本(其第一行可以是shebang #!/bin/bash)。然后任何git xxx调用都会调用该脚本(前提是它在$PATH中)。

OP Tom Hale添加in the comments时,会使用/bin/sh

trace: exec: '/bin/sh' '-c' 'echo Which shell?' 
'echo Which shell?'