Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Can I convince Git Bash to use a specific version of Perl

by Cody Fendant (Friar)
on Sep 03, 2019 at 01:12 UTC ( #11105493=perlquestion: print w/replies, xml ) Need Help??

Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a pre-commit hook for a git repo in perl, on Windows 10 using git bash.

Everything works fine with pure perl but then I tried to use a module and I realise it's using its own, somewhat limited Perl. How can I make git bash use Strawberry Perl for instance? It seems to ignore the shebang line.

But even more mysterious, how is it using Perl at all if it's not reading the shebang line? There's no .pl extension on the file name, and hooks can be in any language.

It appears that git bash is reading the shebang line just enough to figure out that 'perl' is in there somewhere, but not enough to find the perl I want?

  • Comment on Can I convince Git Bash to use a specific version of Perl

Replies are listed 'Best First'.
Re: Can I convince Git Bash to use a specific version of Perl
by stevieb (Canon) on Sep 03, 2019 at 01:19 UTC

    I bet you've got a perl installed here: C:\Program Files\Git\usr\bin. That's installed with Git for Windows. I suspect that git or a related library itself is calling perl for you (possibly something looks into the file?). I'm not sure though.

    You can move the Strawberry Perl PATH environment variables to be read before the Git PATH, or, you can use berrybrew to manage your Perl installations.

Re: Can I convince Git Bash to use a specific version of Perl
by jcb (Deacon) on Sep 03, 2019 at 04:22 UTC

    GNU bash (which is probably the shell bundled with Git on Windows) has a feature for emulating shebang lines, because some *nix systems simply ran all scripts through the shell. Most likely, the shell is looking at your file, finding "perl", searching its PATH for "perl", finding the one bundled with Git, and using it. It is also possible that Git itself may parse shebang lines on Windows.

    I have also written Git pre-commit hooks in Perl in the past, and I have simply avoided using modules and stuck with the baseline language. What are you trying to do with this hook that needs modules?

Re: Can I convince Git Bash to use a specific version of Perl
by choroba (Archbishop) on Sep 03, 2019 at 07:32 UTC
    What about using bash to write the hook?
    #!/bin/bash /path/to/my/perl /path/to/my/script -- "$@"

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Can I convince Git Bash to use a specific version of Perl
by Discipulus (Abbot) on Sep 03, 2019 at 08:41 UTC
    Hello Cody Fendant,

    You already had good answers: I think a PATH modification is appropriate in this case.

    I just want to add you can also use git-cmd.exe on windows which has (un)fortunately no idea at all of what perl is.

    A short command/batch set PATH=D:\perl5.26.64bit\perl\site\bin;D:\perl5.26.64bit\perl\bin;D:\perl5.26.64bit\c\bin;%PATH% run in the resulting console should be enough

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Can I convince Git Bash to use a specific version of Perl
by Anonymous Monk on Sep 03, 2019 at 09:16 UTC
    What shebang are you using exactly?

    #!C:/Program\ Files/Git/usr/bin/sh.exe exec powershell.exe -NoProfile -...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11105493]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2019-12-10 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?