Windows快捷方式以运行Git Bash脚本 [英] Windows shortcut to run a Git Bash script

查看:633
本文介绍了Windows快捷方式以运行Git Bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有运行服务器的test.sh脚本并安装了Git Bash,如何创建Windows快捷方式,双击该快捷方式即可在前台的Git Bash中运行tesh.sh,并允许我查看输出

Assuming I have a test.sh script that runs a server and Git Bash installed, how do I create a Windows shortcut that I can double click to run tesh.sh in Git Bash in the foreground and allows me to see the output of the server?

推荐答案

git bash已经是一个批处理文件,其内容类似于以下内容:

Git bash is already a batch file with content similar to this :

C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i"

如果您要运行(并保持运行)shell脚本在Shell上下文中,在命令行中指定它。诀窍在于,解释脚本文件名时,它将使用 Windows路径,而不是sh / Git环境中的等效路径。

If you want run (and leave running) a shell script in the context of the shell, specify it at the command line. The trick is that when the script file name is interpreted, it uses the Windows path, not the equivalent path in the sh/Git environment.

换句话说,要在Git shell中运行文件 D:\temp\test.sh 并使其运行,创建此批处理文件:

In other words, to run the file D:\temp\test.sh in the Git shell and leave it running, create this batch file :

C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i -- D:\temp\test.sh"

另一方面,如果您想运行脚本并找回外壳,则应该:

On the other hand, if you want to run a script and get your shell back, you should :


  1. 按原样打开外壳

  2. 编辑或创建〜/ .profile (尝试 vi〜/ .profile

  3. 添加此行:〜/ test.sh (如果需要,请忽略路径)

  1. Open the shell as is
  2. Edit or create ~/.profile (try vi ~/.profile)
  3. Add this line : ~/test.sh (ajdust the path if needed)

因此,使用 .profile 看起来像这样:

So with a .profile that looks like this :

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 ~
$

这篇关于Windows快捷方式以运行Git Bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆