Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here is my original question at StackOverflow.com

This is the script I wrote

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

and output is

PATH 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

2 Answers 2

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

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

Your Answer

 
discard

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