ixe*_*013 64
Git bash已经是一个批处理文件,其内容与此类似:
C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i"
Run Code Online (Sandbox Code Playgroud)
如果要在shell的上下文中运行(并保持运行)shell脚本,请在命令行中指定它.诀窍是,当解释脚本文件名时,它使用Windows路径,而不是sh/Git环境中的等效路径.
换句话说,要D:\temp\test.sh在Git shell中运行该文件并使其保持运行,请创建此批处理文件:
C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i -- D:\temp\test.sh"
Run Code Online (Sandbox Code Playgroud)
另一方面,如果你想运行一个脚本并让你的shell回来,你应该:
~/.profile(尝试vi ~/.profile)~/test.sh如果需要,请调整路径)所以.profile看起来像这样:
echo Executing .profile
/bin/sh ~/test.sh
Run Code Online (Sandbox Code Playgroud)
而且test.sh,看起来像这样:
echo Hello, World!
Run Code Online (Sandbox Code Playgroud)
你会得到这个提示:
Welcome to Git (version 1.7.11-preview20120710)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
Executing .profile
Hello, World!
ixe013@PARALINT01 ~
$
Run Code Online (Sandbox Code Playgroud)
qua*_*oft 26
其他答案有效,但有一个较短的解决方案,完全回答了这个问题:
如何创建一个Windows快捷方式,我可以双击以
tesh.sh在Git Bash中运行
的回答是:将以下命令添加到Target:快捷的领域:
"C:\Git\bin\sh.exe" -l "D:\test.sh"
Run Code Online (Sandbox Code Playgroud)
在哪里,-l是的缩写--login.
要更好地理解此命令的作用,请参阅有关调用Bash的官方GNU文档:
-l(--login):使这个shell表现得像登录直接调用一样.当shell是交互式的时,这相当于启动一个登录shellexec -l bash.当shell不是交互式时,将执行登录shell启动文件.exec bash -l或者exec bash --login将用Bash登录shell替换当前的shell.
另请注意:
sh.exe或在PATH环境变量中拥有它(正如其他人已经指出的那样).-i选项我认为最好的解决方案:
请执行下列操作:
mintty.exe例如,在桌面上创建快捷方式.它被发现%installation dir%/Git/usr/bin/mintty.exe
编辑快捷方式的属性并更改目标(保留路径):
"C:\Program Files\Git\usr\bin\mintty.exe" -h always /bin/bash -l -e 'D:\folder\script.sh'
参数说明:
-h always 在脚本完成时保持窗口打开,因此当您仍在读取输出时窗口不会消失(如果您不需要读取输出并希望窗口自动关闭,则移除).
-l 使这个shell表现得像登录直接调用一样.
-e如果管道返回非零状态(更多信息),则立即退出.
我建议使用环境变量%ComSpec%,而不是绝对路径cmd:
%ComSpec% /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login -i"
Run Code Online (Sandbox Code Playgroud)
甚至只是cmd命令,通常可以从%PATH%获得:
cmd /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login -i"
Run Code Online (Sandbox Code Playgroud)
如果您C:\Program Files (x86)\Git\bin添加到PATH(这也是常见的解决方案和TortoiseGit安装的一个案例),您可以使用:
cmd /c "sh --login -i"
Run Code Online (Sandbox Code Playgroud)