Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my original question at

This is the script I wrote

#!/usr/bin/env bash
GP=`/usr/bin/which git`
echo "PATH IS: ${GP}"
echo "PWD IS: ${PWD}"

and output is

PWD IS: /Users/user/tmp

So the question is how to get which git output? I'm running it on Mac OS X 10.6.2.

share|improve this question
maybe i'm missing something, but why do u have #!/usr/bin/env bash at the beginning, shouldn't u use #!/usr/bin/bash? – Roy Rico Mar 12 '10 at 21:04
First, I'd assume that 'which' is in your path (and if it isn't, you can safely assume your path is screwed up, which means that 'which' won't work right anyway), so I'd remove the absolute path. Does running 'which git' work from the command line? Also, the curley braces aren't strictly necessary in that particular case. You could just say echo "PATH IS: $GP" and it will work fine. – Matt Simmons Mar 13 '10 at 19:38

If git isn't located in a directory listed in your $PATH variable, which will be unable to locate it.

The PATH is affected by the following circumstances:

  • Login shell
  • Non-interactive (login) shell
  • Rootshell

Typically specified in /etc/profile. Also can be affected by ~/.bashrc for a non-interactive shell and ~/.bash_profile for a login shell.

share|improve this answer
to debug, add echo "\$PATH IS: ${PATH}" – Roy Rico Mar 12 '10 at 21:03
On osx, also check ~/.profile. – Brendan Martens Mar 12 '10 at 21:31

Use type (a Bash builtin) instead of which:

gp=$(type -P git)

If you use type -a the result will show aliases, functions and more than one executable if alternates exist. You can parse the output if necessary.

Don't set PWD - it's already set by Bash. In fact, I recommend not using all-caps variable names in order to avoid naming collisions with Bash's variables.

# no need to set PWD, it's already set by Bash
echo "PWD IS: ${PWD}"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.