Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I've written a little utility in haXe + Neko that needs to execute some GIT commands. To avoid hardcoding the path to the GIT executable I'd like to use the which command to find out where it is. Everything works as expected when running manually from the console, but not when the the app runs on a cron job.

I'm aware of the restricted environment (here or here) when you run a script using cron, but still surprised this doesn't work:

/usr/bin/which git >> /home/user/git.txt

The text file is created but the content is empty. Again, when run from the console it works as expected.

Any ideas? I'm running OS X Leopard, if that helps.

Thanks : )


share|improve this question
up vote 3 down vote accepted

If 'which' could find the executable, then so could the shell interpreter that is running your cron command. So I don't see why you'd want to use 'which' for this purpose. But maybe you have some reason that is not apparent.

The 'which' command uses the directories listed in $PATH to search for the 1st occurrence of a command. Very likely PATH is not set to what you think it is. Try adding '/usr/bin/env >> /home/user/you/env.txt' to your crontab to run today, one minute from now. Then look in /home/user/you/env.txt to see what PATH was set to. If that PATH is not suitable for your purposes you may have to put all your commands in a small shell script where you can set PATH yourself. You can also look in that env.txt file for other exported environmental variables as that might come in handy, depending on what you want to do via your crontab.

share|improve this answer
Doh! Thanks for pointing out the silly mistake. – Juan Delgado Apr 27 '10 at 10:46

Where is git actually located (i.e. if you run /usr/bin/which git from the console, what does it print)? If it's not in a directory in $PATH (which is just /usr/bin and /bin on my Snow Leopard machine), /usr/bin/which won't find it, and you need to either hardcode it or add a line like


to the crontab file.

share|improve this answer

Would this do the trick?

/usr/bin/env  git

The env command takes care of finding the command, and is itself always in /usr/bin (so I've been told...) This is a common trick in Python scripts, necessary due to different distro putting python in different places, but no one wants to monkey around trying to find where.

share|improve this answer
No. The problem is that cron overrides the user's PATH. env only helps if the program is in the PATH. – Mikel Dec 17 '10 at 0:22

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.