kakyo
kakyo

Reputation: 11590

bash: Apostrophe in path

On Mac OS X (bash 4.2), I try to cd into a folder with an apostrophe in the path:

cd "~/Documents/study/new/Beej's Guide to Unix IPC_code/examples"

Then I got

-bash: cd: ~/Documents/study/new/Beej's Guide to Unix IPC_code/examples: No such file or directory

I also tried escaping the apostrophe like this:

cd "~/Documents/study/new/Beej\'s Guide to Unix IPC_code/examples"

with the result:

-bash: cd: ~/Documents/study/new/Beej\'s Guide to Unix IPC_code/examples: No such file or directory

The only thing worked for me was hard escaping the white spaces and the apostrophe without double-quotes around like this:

cd ~/Documents/study/new/Beej\'s\ Guide\ to\ Unix\ IPC_code/examples

In this case, is there a way I can avoid hard escaping at all?

Upvotes: 2

Views: 5521

Answers (2)

Gordon Davisson
Gordon Davisson

Reputation: 125788

The tilde (~) won't be expanded inside quotes, so you need to leave it outside the quotes. Any of these will work:

cd ~/"Documents/study/new/Beej's Guide to Unix IPC_code/examples"
cd ~/Documents/study/new/"Beej's Guide to Unix IPC_code"/examples
cd ~/Documents/study/new/Beej"'s Guide to Unix "IPC_code/examples

Upvotes: 6

iamauser
iamauser

Reputation: 11479

Which version of bash do you have ? Like @MaxLeske said, it works with autocomplete on version 3.2.48.

Remove the tilde (~) character inside the double quote. Instead give a full path.

cd "/Users/<uname>/Documents/study/new/Beej's Guide to Unix IPC_code/examples"

Upvotes: 0

Related Questions