Question

I have a post-commit hook that works, but for some reason the following line of code is not working properly. It creates my test file regardless of a fail.

!#/bin/sh

# force a failure
ifconfig -z 1>/dev/null 2>&1

if [ $? -ne 0 ]
then
   touch ~/Desktop/fail.txt
fi

The fail.txt file is created with or without that -z. However, if I run this same code without executing via my post-commit hook, it works as it should.

Any suggestions?

Was it helpful?

Solution

Hook scripts execute in an empty environment, including an empty or severely limited PATH. As a result, your script most likely can't find/can't execute ifconfig.

Specify full paths to everything within your hook scripts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top