运行 Git Bash 脚本的 Windows 快捷方式

标签 windows shell desktop msysgit git-bash

假设我有一个运行服务器并安装了 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,您应该:

  1. 按原样打开 shell
  2. 编辑或创建 ~/.profile(尝试 vi ~/.profile)
  3. 添加这一行:~/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/

相关文章:

linux - 'grep'如何连续流?

linux - 这是哪个主题或桌面环境?

python - 如何在列中打印嵌套的 python 列表

Python 3 - 类型错误 : can only concatenate str (not "bytes") to str

windows - 在 Windows 中隐藏 Linux 隐藏文件

c++ - 解析文件路径的最佳方法是什么?

javascript - 处理电话 : anchor

C#:替换 ListView 中空白项的文本?

linux - xargs 不一致的行为和 -n1 参数

linux - Shell脚本时间控制