Bash script to cd to directory with spaces in pathname

后端 未结 13 1707
旧时难觅i
旧时难觅i 2020-11-28 21:14

I\'m using Bash on macOS X and I\'d like to create a simple executable script file that would change to another directory when it\'s run. However, the path to that director

13条回答
  •  一生所求
    2020-11-28 21:20

    You can use any of:

    cd ~/"My Code"
    cd ~/M"y Code"
    cd ~/My" Code"
    

    You cannot use:

    cd ~"/My Code"
    

    The first works because the shell expands ~/ into $HOME/, and then tacks on My Code without the double quotes. The second fails because there isn't a user called '"' (double quote) for ~" to map to.

提交回复
热议问题