I need to run a certain command when a push is received in a repository. That binary is located at a custom path which I added to .bashrc and works normally from the shell. I wrote a little script as a git hook. However, the .bashrc additions don't seem to affect this script.
I've tried putting bash ~/.bashrc
at the top of the script but didn't work. If I run the script manually, say $ sh post-receive
, it works just fine. What is wrong?
Check your .bashrc In some distrib, the end of the script is skipped when not exec in interactive mode. Just bring the usefull stuff you need over the skip part.
It looks to that:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
The script is probably run as a different user, or is being invoked with options to disable interactive features and/or startup scripts. That's as it should be; nothing is "wrong" here really.
You can add . /home/you/.bashrc
as a quick and dirty workaround; or, more properly, just amend the script's PATH directly; or, even more properly, modularize dependencies e.g. by putting the code in a separate file which you source both from your .bashrc
and from this script - but for this isolated case, that´s certainly overkill.
The command to "include" a file of shell scipt is called "source" or "dot"; in Bash, source
is available as a synonym, but in proper Bourne shell, it's a literal dot (aka period, full stop):
. /path/to/stuff
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With