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.

mpersico
  • 766
  • 7
  • 19

1 Answers1

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
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • Oh DUH! to me. Thanks. – mpersico Jul 06 '17 at 14:17
  • 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. – Raman Sailopal Jul 06 '17 at 14:18
  • @RamanSailopal You can also use `/usr/bin/env` to do that on the fly; added that to the answer. – Dan Lowe Jul 06 '17 at 14:19
  • 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 (https://stackoverflow.com/questions/10978257/extending-git-functionality) – mpersico Jul 06 '17 at 14:58
  • 1
    @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. – torek Jul 06 '17 at 16:37
  • @torek: Yes you are correct. My choices are to stop using the functions, convert them to non-functions or not to covert my git functions to git extended commands. – mpersico Jul 06 '17 at 21:24