【发布时间】:2015-11-06 22:41:04
【问题描述】:
在Windows 10,使用Git-2.4.6-5th-release-candidate-64-bit.exe,如果我这样做:
set GIT_SSH=D:\ssh.sh
我明白了:
error: cannot spawn D:\ssh.sh: No such file or directory
fatal: unable to fork
但如果我改为这样做:
set GIT_SSH=D:\ssh.exe
或:
set GIT_SSH=D:\ssh.bat
一切都按预期进行。
我的PATHEXT:
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.sh
已应用的注册表文件:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\Applications\bash.exe]
[HKEY_CURRENT_USER\Software\Classes\Applications\bash.exe\shell]
[HKEY_CURRENT_USER\Software\Classes\Applications\bash.exe\shell\open]
[HKEY_CURRENT_USER\Software\Classes\Applications\bash.exe\shell\open\command]
@="\"C:\\sdk\\Git\\bin\\bash.exe\" \"%1\" %*"
[HKEY_CURRENT_USER\Software\Classes\Applications\sh.exe]
[HKEY_CURRENT_USER\Software\Classes\Applications\sh.exe\shell]
[HKEY_CURRENT_USER\Software\Classes\Applications\sh.exe\shell\open]
[HKEY_CURRENT_USER\Software\Classes\Applications\sh.exe\shell\open\command]
@="\"C:\\sdk\\Git\\bin\\sh.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\sh_auto_file]
[HKEY_CLASSES_ROOT\sh_auto_file\shell]
[HKEY_CLASSES_ROOT\sh_auto_file\shell\open]
[HKEY_CLASSES_ROOT\sh_auto_file\shell\open\command]
@="\"C:\\sdk\\Git\\bin\\sh.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\sh_auto_file\ShellEx]
[HKEY_CLASSES_ROOT\.sh]
@="sh_auto_file"
[HKEY_CLASSES_ROOT\.sh\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,69,00,6d,00,\
61,00,67,00,65,00,72,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,36,\
00,38,00,00,00
[HKEY_CLASSES_ROOT\.sh\shell\edit]
[HKEY_CLASSES_ROOT\.sh\shell\edit\command]
@="\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\" \"%1\""
这些的结果是,如果我打开cmd并输入:
D:\ssh.sh
甚至:
D:\ssh
脚本被执行。
但 git 拒绝使用 shell 脚本,但满足于使用 .exe 文件和 .bat 文件。
这是为什么?这是一个错误,还是我错过了什么?
【问题讨论】:
-
cmd突然运行 shell 脚本?还是 git bash 正在运行 shell 脚本? -
您可以从
cmd调用batch脚本,就像您可以调用python脚本或shell脚本一样——这没有区别。当cmd遇到批处理脚本时,它知道如何处理它...注册表文件+我提供的PATHEXT主要是您需要处理shell文件,除了shebang(@ 987654345@) 部分。 -
它确实有所作为 - 因为您不能 - 默认情况下 - 通过运行
D:\ssh.sh来调用 shell 脚本。所以我很好奇你是否为.sh文件设置了处理程序? -
是的,这就是注册表内容 + PATHEXT 所做的。将
.sh添加到PATHEXT 中,这样您就可以在cmd中调用kaboom.sh作为kaboom。注册表中的sh_auto_file文件部分使得Git for Windows提供的sh程序可以处理.sh脚本。 -
您可以对
python执行相同的操作,甚至可以对您认为可执行的所有文件使用通用的 shebang 处理程序(Windows 权限有点缺陷......)
标签: windows git shell batch-file ssh