1

I am trying to run a git bash file in Windows 7, 64-bit. The file is below. The command is:

git test-bash

When the command is entered, there is a pause of no more than a second, then the prompt returns. There is no output to the terminal and no file created. What am I doing wrong?

file git-test-bash:

#!/bin/bash
# start
printf "test-bash-printf"
echo "test-bash-echo"
echo "test-bash-echo-to_file" > /d/Users/joeuser/bin/file.txt
Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
  • 1
    `git test-bash` != `git-test-bash` unless you are writing that as a git subcommand. Are you sure your script is being run? Where does the script live? What is the exit status of `git test-bash`? – Etan Reisner Sep 10 '15 at 20:42
  • No I am not sure if the script is being run, hence the question. My understanding is that in order to run a file named "git-any-text-here" one enters the command as "git any-text-here" (without the space after git). The script is in /d/Users/joeuser/bin/ and this directory is on the PATH.How do I determine the exit status? – Al Lelopath Sep 10 '15 at 20:58
  • @AlLelopath, The exit code of the last command is available in `$?` (see http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line). If you append `-x` to the first line (`#!/bin/bash -x`) you get a trace of the issued commands and their result, which can be helpfull to debug the code. – joran Sep 10 '15 at 21:33

1 Answers1

2

I just tested git-test-bash in a regular DOS session, or in a shell session (calling c:\prgs\git\PortableGit-2.5.1-64-bit\git-bash.exe).

It does work (except you might want to add '\n' in order to put the printf in its own line)

#!/bin/bash
# start
printf "test-bash-printf\n"
echo "test-bash-echo"
echo "test-bash-echo-to_file" > /C/Users/VonC/prog/file.txt

You only have to make sure %PATH% (meaning in DOS session) includes the folder where git-test-bash is.

Output:

C:\Users\vonc\prog\b2d>git test-bash
test-bash-printf
test-bash-echo

Or in bash shell session:

vonc@bigvonc MINGW64 ~/prog/b2d (master)
$ git test-bash
test-bash-printf
test-bash-echo

Try it with a recent git-for-windows though.
I used the latest 2.5.1.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250