In this video, we'll talk about escaping of special characters.
So we have just talked about expansion.
And in expansion, there are special characters that are interpreted by the shell to attribute
a special meaning to the variables.
But sometimes, you just need to type $. Normally, when the shell sees $, it's going to interpret.
But if you want to just type $, you need to escape it.
In escaping, the special meaning of the characters is taken away.
You have double quotes.
Double quotes suppress globbing in shell expansion, but they do allow command and variable substitution.
There is single quotes.
It takes away the special meaning of any characters.
And there is backslash, which protects only the following character from expansion.
Let me show you.
So what happens when I type echo $? Well, $ is a wildcard, and the interpretation is
all false in the current directory.
So what can I do if I really want to print $?
I'll put a backslash in front of it.
Another way is just to put it between single quotes.
And if you put it between single quotes, the result is the same, but it's nice because
it takes away the meaning of everything.
And there you can see it's literally printing everything.
That wouldn't happen if you would only use a backslash, where you do take away the meaning
of the start, but not of the $ path.
Now we have the double quotes.
Double quotes suppress globbing in shell expansion, but do allow command and variable substitution.
So what does that mean?
Well, if we put this entire string between double quotes, then you can see that it does
interpret the $ path, it does not interpret the wildcard.
Double quotes are a little bit confusing.
And I would advise, if you want to take away the meaning of everything, just use single
quotes.
And if you merely want to take away the meaning of spaces, then you put it between double
quotes.
And that should be enough in most cases.