假设我有一个运行服务器并安装了 Git Bash 的 test.sh 脚本,我如何创建一个 Windows 快捷方式,我可以双击它在前台的 Git Bash 中运行 tesh.sh 并允许我查看输出服务器?
最佳答案
Git bash 已经是一个批处理文件,内容类似这样:
C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i"
如果您想要在 shell 上下文中运行(并保持运行)shell 脚本,请在命令行中指定它。诀窍在于,当解释脚本文件名时,它使用 Windows 路径,而不是 sh/Git 环境中的等效路径。
换句话说,要在 Git shell 中运行文件 D:\temp\test.sh
并让它保持运行,创建这个批处理文件:
C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i -- D:\temp\test.sh"
另一方面,如果您想运行脚本并取回您的 shell,您应该:
- 按原样打开 shell
- 编辑或创建
~/.profile
(尝试vi ~/.profile
) - 添加这一行:
~/test.sh
(如果需要,添加路径)
所以 .profile
看起来像这样:
echo Executing .profile
/bin/sh ~/test.sh
和 test.sh
看起来像这样:
echo Hello, World!
你会得到这个提示:
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 ~
$
关于运行 Git Bash 脚本的 Windows 快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21564275/