How to cd into a directory with space in the name?

前端 未结 14 2341
独厮守ぢ
独厮守ぢ 2020-11-27 05:30

I\'m attempting to get into the directory /cygdrive/c/Users/my dir/Documents:

$ DOCS=\"/cygdrive/c/Users/my\\ dir/Documents\"

$ echo $DOCS
/cyg         


        
14条回答
  •  萌比男神i
    2020-11-27 06:18

    As an alternative to using quotes, for a directory you want to go to often, you could use the cdable_vars shell option:

    shopt -s cdable_vars
    docs='/cygdrive/c/Users/my dir/Documents'
    

    Now, to change into that directory from anywhere, you can use

    cd docs
    

    and the shell will indicate which directory it changed to:

    $ cd docs
    /cygdrive/c/Users/my dir/Documents
    

提交回复
热议问题