3

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

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

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

Example shell using MINGW32 shell:

$ echo $SHELL
/bin/sh

Example shell using 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?

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

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Angus Comber
  • 9,316
  • 14
  • 59
  • 107

1 Answers1

2

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

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

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;

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried with script called git-abc.sh with #!/bin/sh topline and some git commands but if I run from cmd.exe I get: fatal: Uh oh. Your system reports no Git commands at all. – Angus Comber Jan 07 '16 at 10:51
  • @AngusComber not `git-xxx.sh`. `git-xxx` (no extension). You invoke that script by typing `git xxx` (`git` space `xxx`) – VonC Jan 07 '16 at 11:09