Search code examples
perlcygwin

Changing the Cygwin environment variable to 'perl'


To execute Perl, I use

/cygdrive/c/Perl64/bin/perl.exe

Is there a way to replace that whole line with just perl?


Solution

  • export PATH="/cygdrive/c/Perl64/bin:$PATH"
    

    Note that you might want to install cygwin's own build of Perl. If you continue using this Windows build of Perl, you'll need to pass Windows paths to it. If you need an automated means of converting cygwin paths to Windows paths, use cygpath.

    # XXX
    $ perl /home/ikegami/a.pl
    Can't open perl script "/home/ikegami/a.pl": No such file or directory
    
    # OK
    $ perl "$( cygpath -w '/home/ikegami/a.pl' )"
    Hello, World!
    

    Handling variable lists arguments is harder.

    # XXX
    $ perl -E'for (@ARGV) { say "$_: ", -e()?1:0 }' "/cygdrive/c/Program Files"/*
    /cygdrive/c/Program Files/ATI: 0
    /cygdrive/c/Program Files/Common Files: 0
    ...
    
    # OK
    $ cygpath -w "/cygdrive/c/Program Files"/* | xargs -d"\n" \
        perl -E'for (@ARGV) { say "$_: ", -e()?1:0 }'
    C:\Program Files\ATI: 1
    C:\Program Files\Common Files: 1
    ...