Search code examples
bashwindows-7cygwinaliasaliases

Why can't I 'cd' into Bash aliases on Cygwin?


I'm using Bash via the mintty terminal on Cygwin, and I've created two aliases in my .bashrc file in my Cygwin home directory.

alias croot="C:/cygwin64"
alias desktop="B:/Users/User/Desktop"

When I enter croot or desktop into the terminal, it seems to work fine:

B:/Users/User/Desktop: Is a directory

However, using those aliases with something like cd croot returns the error:

-bash: cd: croot: No such file or directory

What's going on here?


Solution

  • alias doesn’t work the way you think it does. Do this:

    alias croot='cd C:/cygwin64'
    croot
    

    Or:

    croot=C:/cygwin64
    cd "$croot"
    

    Result:

    $ pwd
    /