哪个shell用于git'!'别名? [英] Which shell used for git '!' aliases?
问题描述
在执行以!
?
git
使用了什么默认shell?我怀疑它是/ bin / sh,因为在别名中使用 read
时,在我的shell中获得不同的行为它是 bash
)。
+ ravi @ boxy:〜/。 dotfiles(master *%u + 2)$ grep'test ='〜/ .gitconfig
test =!f(){read -n1 -pWorks?r;}; f
+ ravi @ boxy:〜/ .dotfiles(master *%u + 2)$ git test
f(){read -n1 -p Works? R等}; f:1:阅读:非法选项-n
+ ravi @ boxy:〜/ .dotfiles(master *%u + 2)[2] $ read -n1 -pWorks? R等#在当前shell(bash)中试试它
Works?Y + ravi @ boxy:〜/ .dotfiles(master *%u + 2)$#OK,那就工作了...
+ 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是shell内建的
+ ravi @ boxy:〜/ .dotfiles(master * u + 2)$读取
+ ravi @ boxy:〜/ .dotfiles(master *%u + 2)[1] $#none,那为什么shell有不同的表现呢?
+ ravi @ boxy:〜/ .dotfiles(master *%u + 2)[1] $ git sh bash -c read -n1
嗯,这没关系?
+ ravi @ boxy:〜/ .dotfiles(master *%u + 2)$#是的,工作。
如何设置哪个shell用于处理以开头的别名! / code>?
如此处所述,您可以看到更多内容:
GIT_TRACE = 1 git test
解决方法是创建一个名为git-xxx的shell脚本(其第一行可以是shebang #!/ bin / bash
)。然后,任何 git xxx
调用都会调用该脚本(只要它位于 $ PATH
中)。
正如 OP Tom Hale 添加在评论, What default shell is used by I'm suspecting it's /bin/sh, because I'm getting different behaviour when using How can I set which shell is used in processsing aliases beginning with As described here, you can see more with: The workaround is to create a shell script (whose first line can be a shebang As the OP Tom Hale adds in the comments,
这篇关于哪个shell用于git'!'别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! / bin / sh 使用code>:
$ b $ pre $ trace:exec:'/ bin / sh''-c''echo哪个shell ?'
'echo哪个shell?'
git
when executing an alias starting with !
?read
in an alias vs in my shell (which is 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.
!
?GIT_TRACE=1 git test
#!/bin/bash
) named git-xxx. Then any git xxx
call would invoke that script (provided it is in the $PATH
)./bin/sh
is used: trace: exec: '/bin/sh' '-c' 'echo Which shell?'
'echo Which shell?'