简体   繁体   English

如何运行可确定cmd.exe或gnu mingw shell是否正在运行的脚本

[英]How to run a script which can determine whether cmd.exe or gnu mingw shell is running

I want to write a script which runs some git commands on Windows 7 platform. 我想编写一个在Windows 7平台上运行一些git命令的脚本。

The users have git tools installed or at least MINGW - the minimalist GNU for Windows. 用户安装了git工具或至少MINGW - Windows的极简主义GNU。

The trouble is that some users run from the MINGW32 shell and others from cmd.exe. 问题是某些用户从MINGW32 shell运行,而其他用户则从cmd.exe运行。

Example shell using MINGW32 shell: 使用MINGW32 shell的示例shell:

$ echo $SHELL
/bin/sh

Example shell using cmd.exe 示例shell使用cmd.exe

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

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? 有什么方法可以从我的初始脚本确定shell,然后可能运行Windows批处理文件或其他unix脚本?

Or another idea is to assume user will use git bash and just check $SHELL is /bin/sh. 或者另一个想法是假设用户将使用git bash并且只检查$ SHELL是/ bin / sh。 Is that easier? 那更容易吗?

One trick I used is to name your sh script git-xxx . 我使用的一个技巧是命名你的sh脚本git-xxx
(Replace xxx by a sensible name). (用合理的名称替换xxx)。 Start your script with #!/bin/sh . 使用#!/bin/sh启动脚本。

That way, you can launch ' git xxx ' ( git space xxx ) from a git-bash or a CMD session: it will use the MINGW shell every time. 这样,您可以从git-bash或CMD会话启动' git xxx '( git space xxx ):它每次都会使用MINGW shell。

Make sure that git-xxx (no extension) is in your %PATH% . 确保git-xxx (无扩展名)在%PATH%
And you PATH should also include <path/to/git/bin> and <path/to/git/usr/bin> . 而你的PATH还应包括<path/to/git/bin><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;

That last path has more than 200 unix commands compiled for Windows. 最后一个路径有超过200个为Windows编译的unix命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM