0

On my systems, putting a shell script git-foo in directory /home/me/mygits (nothing special about the name) on your path causes the command

git foo 

to evaluate to

/bin/sh /home/me/mygits/git-goo 

I use a lot of bash shell functions in my programming and even though I export -f the functions, they don't make it to the shell started up by the git functionality.

I was wondering if there was any way to control what shell gets started when the command that is being executed is a shell script? That may not help in the end, but I'd like to try a few experiments before giving up.

Thank you.

1 Answer 1

2

Yes, you can use whatever you want (including Perl, Python, etc). Just add

#!/bin/bash 

as the first line of the script.

Or you can use something like this to find a command in $PATH without specifying it at a static path.

#!/usr/bin/env bash 
Sign up to request clarification or add additional context in comments.

6 Comments

Oh DUH! to me. Thanks.
To elaborate, use the "whereis" command i.e. "whereis python" to get the path to the executable and then add this after #! in the script.
@RamanSailopal You can also use /usr/bin/env to do that on the fly; added that to the answer.
These are all correct, but I fear that none will actually help the situation. Each of these is going to start up a new process, not a subshell of the current process. Hence, all exports will be lost. What I REALLY need is to eval the script in the context of the calling process. But that would involve some type of exec call by git to pull that off. I have to take a look at the git code handling all of this, which I can get from another answer (stackoverflow.com/questions/10978257/…)
@mpersico: Hence, all exports will be lost There is nothing you can do about this: environment variables are strictly hierarchical. Even a subshell of the current (Git command in C or shell) process does not affect its parent. A few programs, such as git filter-branch, deliberately run commands in a way that allows them to affect itself (filter-branch is itself a shell script and uses eval) but most assume, and even depend-on, this kind of separation.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.