$ PATH extended in .bashrc not available in git hook script

I need to run a specific command when the push file is received in the repository. This binary is located in a special path that I added to .bashrc and works normally with the shell. I wrote a little script as a git hook. However .bashrc add-ons do not seem to affect this script.

I tried placing bash ~/.bashrc at the top of the script, but did not work. If I run the script manually, say $ sh post-receive , it works fine. What's wrong?

+3
source share
4 answers

The script is probably launched as another user or called with options to disable interactive functions and / or startup scripts. It is as it should be; there is nothing wrong with that.

You can add . /home/you/.bashrc . /home/you/.bashrc as a quick and dirty workaround; or, more correctly, just make changes to the PATH script directly; or, more correctly, modulate dependencies, for example. by putting the code in a separate file, which you use both from your .bashrc and from this script, but for this isolated case this is definitely overkill.

The command "include" command line file is called "source" or "point"; in Bash, source is available as a synonym, but in the correct Bourne shell, this is a literal dot (aka period, full stop):

 . /path/to/stuff 
+3
source

That bash ~/.bashrc spawns a new shell that executes a file called .bashrc , and any state inside this subshell is naturally lost when this subshell exits - what should it do before proceeding to the second line of your actual script, which contains the call.

+2
source

Check your .bashrc On some distributions, the end of the script is skipped when not being executed interactively. Just bring the useful material you need over the pass part.

It looks like this:

 # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac 
+2
source

@Clem's answer saved my day - I did not suspect that my ~/.bashrc prematurely. Thanks!

0
source

Source: https://habr.com/ru/post/1490169/


All Articles