5

To display current directory I am using $pwd which is working fine in Cygwin.

This document is explaining how to convert cygwin directory to windows format. But why $cygpath -w pwd and $cygpath -w $pwd is not working?

It is what I am getting in that case:

enter image description here

Sergino
  • 10,128
  • 30
  • 98
  • 159

3 Answers3

10

try any of these versions:

cygpath -w "$(pwd)"
cygpath -w "$PWD"
cygpath -w "`pwd`"
anishsane
  • 20,270
  • 5
  • 40
  • 73
  • would you please explain why non of these `$cygpath -w pwd` and `$cygpath -w $pwd `was't working however if I run `$pwd` it is displaying current directory – Sergino Dec 15 '15 at 12:39
  • 1
    ^^ http://stackoverflow.com/questions/4651437/how-to-set-a-bash-variable-equal-to-the-output-from-a-command – anishsane Dec 15 '15 at 14:49
  • 1
    `cygpath -w $(pwd)` worked for me, the quoted versions don't. – Stephen Jul 24 '17 at 02:10
1

I didn't want to remember cygpath - so i created a wrapper around pwd and added to my .bashrc

pwd()
{
    if [[ $1 == "-W" ]] ; then 
        cygpath -aw .; 
    else 
        wpwd="-W, --winpath\t  Gives you actual Windoze path"
        err_msg=$(/usr/bin/pwd $* 2>&1);
        let "v = $?"
        if [ $v -eq 1 ] ;  then # have error
            echo "${err_msg}" | sed 's/.*pwd --help.*//' ;
            /usr/bin/pwd --help | sed "s|\(.*  -L, --logi.*\)|  $wpwd\n\1|" 
        else 
            echo "${err_msg}"
        fi
    fi
}

`

1

But why $cygpath -w pwd and $cygpath -w $pwd is not working?

Git 2.15.x/2.16 (Q1 2018) illustrates that issue, due to UNC paths being also relevant in Cygwin builds and being now tested just like Mingw builds.

See commit f21d60b (31 Oct 2017) by Adam Dinwoodie (me-and).
(Merged by Junio C Hamano -- gitster -- in commit b169d18, 09 Nov 2017)

t5580: add Cygwin support

t5580 tests that specifying Windows UNC paths works with Git.
Cygwin supports UNC paths, albeit only using forward slashes, not backslashes, so run the compatible tests on Cygwin as well as MinGW.

The only complication is Cygwin's pwd, which returns a *nix-style path, and that's not suitable for calculating the UNC path to the current directory.
Instead use Cygwin's cygpath utility to get the Windows-style path.

That is why the test now uses:

alias winpwd='cygpath -aw .'
BACKSLASHED="$(winpwd | tr / \\\\)" 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250