Running rm projects/artwork/My Project (543893)/Images/*.png
at the command line in Debian does not work because of the spaces and the parenthesis. I need to escape them. But I thought quotation marks “” were an alternative to escaping. It works with other commands, such as cd
, but not with rm
. Why is that?
2
Answers
Because globbing does not work with quoting:
You should ensure that:
the spaces and parentheses are inside the quotation marks, so that they are treated as literals, because otherwise these characters will have special meanings for the shell (spaces to separate command-line arguments, and parentheses for a subshell command)
but for the
*
you want the exact opposite: it must be outside the quotation marks so that it is indeed given its special meaning as a wildcard, not a literal*
.Remember that you do not need to apply quotation marks to the whole string, only the part that needs treating as a literal and otherwise would be given a special meaning by the shell.
So for example you could use:
Similarly, if you use escapes, escape the spaces and parentheses, but not the wildcard:
(In other words, you would not use
*
.)