What is the difference between
grep apple file and
grep "apple" file? What does putting the quotation marks do? They both appear to work and do the exact same thing (display same line).
The quotation marks have an effect on what characters your shell considers special and to have a syntactic meaning. In your example this doesn't make a difference because
But consider another example:
Double quotes allow evaluation, single quotes prevent evaluaton, no quotes allow wildcard expansion, when used on command line. As contrived examples:
Understanding the way quotes work is pivotal to understanding Bash. For example:
You can use single quotes to pass a command via a variable. Single quotes will prevent evaluation. Double quotes will evaluate.
You can use single quotes inside double quotes and you can use double quotes inside double quotes, but double quotes inside single quotes should not be done (without escaping them).
You'll need to gain a thorough understanding of quotes to use Bash effectively. Very important!
As a general rule, I don't use quotes if I want Bash to expand something into elements (like an array), I use single quotes for literal strings that are not to be altered, and I make liberal use of double quotes for variables that are likely to return any type of string. This is to ensure that spaces and special characters will be preserved.