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
3
  • 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? Commented Sep 10, 2015 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? Commented Sep 10, 2015 at 20:58
  • @AlLelopath, The exit code of the last command is available in $? (see stackoverflow.com/questions/334879/…). 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. Commented Sep 10, 2015 at 21:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.