I am calling a Perl script from cygwin. The issue that I am having is that when it calls $ENV{PATH}, the path is receives is a unix path. How do I change my shell so it returns a DOS path?

  • what does change my shell mean? where is it that you think you need a DOS path? – ysth Feb 20 '14 at 22:12

Cygwin is a Unix-emulation environment for Windows. It wouldn't work unless $PATH was a Unix-style path.

If you want perl to give you a DOS path, use a DOS-compatible Perl, like Strawberry Perl. You can even run Strawberry Perl (or whatever Windows-build of perl you use) from Cygwin if you want to.


It has nothing to do with the shell, so changing shell won't help, and there's nothing you can change in the shell to help.

>echo %PATH% & perl -E"say $ENV{PATH}"

The purpose of cygwin is to allow unix program to be compiled on a Windows machine with as little changes as possible, which means the system calls must behave as if the program was executing on a unix machine, which means the PATH must look like a unix path.

If you had used a Windows build of Perl (such as ActivePerl or Strawberry Perl), you wouldn't have this problem.

If you wish to continue using a Cygwin build of Perl, you could use the Cygwin tool cygpath to convert the paths for you.

$ perl -E'
    my $cmd = q{IFS=: ; cygpath -w $PATH};
    chomp( my @paths = `$cmd` );
    say for @paths;
  • Why the downvote? – ikegami Feb 20 '14 at 22:21

You can use cygpath and call bash with: (Looks like you have to set IFS.)

` IFS=:; cygpath --windows \$PATH`

Or unsetting IFS.

`IFS=;cygpath --windows --path \$PATH`

Or you could just do it with a few simple rules.

map { 
    # turn cygdrives to drive letter + colon

    # locate the cygwin relative paths to whatever it is on your system.

    $_ = qq("$_") if m/[() ]/; # quote paths where necessary

    # You don't really need to switch the slashes for perl, Java
    # a lot of other multi-platform tools.
} split /:/, $ENV{PATH}

Note that you might have to expand the character set in the match expression.

  • @ikegami works fine from bash. I just cut and pasted it into my bash terminal. Where I got it. – Axeman Feb 20 '14 at 21:51
  • The final solution is incomplete. What's $CYGWIN_HOME? – ikegami Feb 20 '14 at 22:02

I hope this helps, although maybe a bit late :)

Copy the PATH to a Cygwin-unrecognised variable and use that instead:

perl -e 'print join("\n",split(";",$ENV{MYPATH}),"\n")'

Your Answer

