0

This question already has an answer here:

We can a make a directory named $"dollars"&<>\dogs if we surround it with single quotes like the following

mkdir '$"dollars"&<>\dogs'

However, what if I want to include a single quote in the directory name?

If I want my directory name to be $"dollars"&<>/dogs'

Then How can I use the single quoting method do this ?

I tried to do

mkdir '$"dollars"&<>/dogs'' But this didn't work for and also

mkdir ''$"dollars"&<>/dogs'' didn't work either.

I even tried to put a backslash before it, but there was no use !

marked as duplicate by jasonwryan, Archemar, taliezin, chaos, don_crissti Aug 18 '15 at 7:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You can't escape a single quote within single quotes. But you can juxtapose multiple quoted strings and they will be concatenated. So just use single quotes for the part not containing a single quote, then append a single quote escaped with a \, like this:

mkdir '$"dollars"&<>/dogs'\'
1

escape the last quote like so:

mkdir '$"dollars"&<>\dogs'\'
  • Thanks but Why would this work ? – alkabary Aug 18 '15 at 5:34
  • You are escaping the last quote, and so you are telling bash to take it as part of the name of the directory not as part of the string syntax which is 'string'. – VaTo Aug 18 '15 at 16:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.