繁体   English   中英

用于 git '!' 的 shell 别名?

[英]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 -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 ! ?

如此处所述,您可以通过以下方式查看更多信息:

GIT_TRACE=1 git test

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

正如OP Tom Hale 在评论中添加的那样,使用了/bin/sh

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

暂无
暂无

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

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