How to navigate to a directory in C:\ with Cygwin?

前端 未结 13 1751
渐次进展
渐次进展 2020-12-04 04:41

I\'m trying to install PyQt4 so I can mess around with it. The installation guide said I had to install Sip. The last step to installing Sip is to use the make install

相关标签:
13条回答
  • 2020-12-04 05:14

    As you'll probably want to do this often, add aliases into your .bashrc file, like:

    alias cdc='cd /cygdrive/c'
    alias cdp='cd /cygdrive/p'
    

    Then you can just type on the command line:

    cdc
    
    0 讨论(0)
  • 2020-12-04 05:16

    I'll add something that helps me out a lot with cygwin. Whenever setting up a new system, I always do this

    ln -s /cygdrive/c /c
    

    This creates a symbolic link to /cygdrive/c with a new file called /c (in the home directory)

    Then you can do this in your shell

    cd /c/Foo
    cd /c/
    

    Very handy.

    0 讨论(0)
  • 2020-12-04 05:16

    Create a file named "overrideBashCdForWindowsPaths" in your HOME folder. Paste the following lines into that file and save it:

    #!/bin/bash
    
    function cd() {
        CD_PATH="$(history | tail -1 | sed -e "s,.*${FUNCNAME[0]}\s*,,g")"
    
        if [ -z "${CD_PATH}" -o "${CD_PATH}" = "~" ]; then
            CD_PATH="${HOME}"
        fi
    
        builtin cd "$(cygpath "$CD_PATH")"
    }
    

    Next, type the following command in a terminal, while you are in your HOME folder:

    echo ". overrideBashCdForWindowsPaths" >> .bashrc
    

    Close your terminal and open a new one. You can now easily change into that Windows folder by simply typing

    cd C:\Python31\sip
    

    The script reads the last command, extracts the path and passes it to Cygwin's path-conversion tool. By naming the function "cd" we sort of 'override' Bash's builtin "cd" and delegate the actual call to it in the very last line.

    0 讨论(0)
  • 2020-12-04 05:18

    cd c: is supported now in cygwin

    0 讨论(0)
  • 2020-12-04 05:19

    Something that is worth mentioning here is that Cygwin's cygpath, still does not handle spaced Windows paths properly, especially in Bash scripts running under Cygwin. The trick is to understand how Cygwin interprets quotes in Bash scripts.

    The following does not work:

    #!/bin/bash
    TBDIR="/cygdrive/c/Program\ Files\ \(x86\)/MyDir/"
    
    if [ -d "${TBDIR}" ]; then 
        echo "Found MyDir directory at: ${TBDIR}"
        cd "$TBDIR"
    else 
        echo "MyDir program directory not found!"
        echo "Wrong DIR path: ${TBDIR}"
        exit 1
    fi
    

    But this does work:

    #!/bin/bash
    # Cygwin-ism: No quotes!
    TBDIR=/cygdrive/c/Program\ Files\ \(x86\)/MyDir/
    
    if [ -d "${TBDIR}" ]; then 
    ...
    

    As far as I know, there is currently no known workaround using cygpath, that can properly handle spaces in the bash scripting context but you can use quotes in your scripts.

    0 讨论(0)
  • 2020-12-04 05:20

    Use:

    cd /cygdrive/c
    
    0 讨论(0)
提交回复
热议问题