1

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 !

alkabary
  • 1,479
  • 5
  • 19
  • 37

2 Answers2

3

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'\'
user3188445
  • 5,257
1

escape the last quote like so:

mkdir '$"dollars"&<>\dogs'\'
VaTo
  • 3,101
  • Thanks but Why would this work ? – alkabary Aug 18 '15 at 05: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