0

I'm trying to write a script for some of basic git operations, in that getting an issue git status: command not found

I'm trying it on:
- Windows machine
- bash script
- running script from git bash
- git is installed at C:\Program Files\Git\mingw64\bin

Below is the sample script I'm trying with:

path_to_git='/c/Program Files/Git/mingw64/bin/'
PATH=$PATH:$path_to_git
echo $PATH
export PATH

res=$("git status")
echo $res

Please guide me through, thanks

1
  • 3
    Why the double quotes here: res=$("git status")? Commented Mar 12, 2020 at 15:45

1 Answer 1

1

Quoting like you did makes the shell look for a command called git status instead of git with an argument status – drop the double quotes:

res=$(git status)

And then don't echo that without quotes, or it'll remove all linebreaks:

echo "$res"

For scripting, consider using

git status --porcelain

instead (see documentation), with an easier-to-parse output format that is versioned.

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

1 Comment

thanks for your answer. I didn't know this echo "$res" about linebreaks.

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.