如何运行一个脚本,可以确定cmd.exe或gnu mingw shell是否正在运行 [英] How to run a script which can determine whether cmd.exe or gnu mingw shell is running

查看:566
本文介绍了如何运行一个脚本,可以确定cmd.exe或gnu mingw shell是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个脚本,在Windows 7平台上运行一些git命令。

I want to write a script which runs some git commands on Windows 7 platform.

用户已安装git工具,或至少MINGW - Windows的极简GNU。

The users have git tools installed or at least MINGW - the minimalist GNU for Windows.

麻烦的是,有些用户从MINGW32 shell运行,而其他用户则从cmd.exe运行。

The trouble is that some users run from the MINGW32 shell and others from cmd.exe.

使用MINGW32 shell:

Example shell using MINGW32 shell:

$ echo $SHELL
/bin/sh

使用cmd.exe的示例shell

Example shell using cmd.exe

>echo %COMSPEC%
C:\Windows\system32\cmd.exe

有没有什么方法可以从我的初始脚本确定shell,然后可能运行Windows批处理文件或其他unix脚本?

Is there any way I can determine the shell from my initial script and then possibly run a windows batch file or otherwise a unix script?

或者另一个想法是假设用户将使用git bash,只需检查$ SHELL是/ bin / sh。

Or another idea is to assume user will use git bash and just check $SHELL is /bin/sh. Is that easier?

推荐答案

我使用的一个技巧是命名你的sh脚本 git-xxx

(用合理的名称替换xxx)。使用#!/ bin / sh 开始您的脚本。

One trick I used is to name your sh script git-xxx.
(Replace xxx by a sensible name). Start your script with #!/bin/sh.

c> git xxx '( git space xxx )从git-bash或CMD会话:它将每次使用MINGW shell。

That way, you can launch 'git xxx' (gitspacexxx) from a git-bash or a CMD session: it will use the MINGW shell every time.

确保 git-xxx (无扩展)在您的%PATH%

和您 PATH 应包括< path / to / git / bin> < path / to / git / usr / bin>
例如:

Make sure that git-xxx (no extension) is in your %PATH%.
And you PATH should also include <path/to/git/bin> and <path/to/git/usr/bin>. For instance:

C:\prgs\git\PortableGit-2.7.0-64-bit\bin;C:\prgs\git\PortableGit-2.7.0-64-bit\usr\bin;

最后一个路径有超过200个为Windows编译的unix命令。

That last path has more than 200 unix commands compiled for Windows.

这篇关于如何运行一个脚本,可以确定cmd.exe或gnu mingw shell是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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