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).
Ubuntu – the difference between grep apple file and grep “apple” file
bashgrepsh
Related Question
- Ubuntu – difference between bash.bashrc and /etc/environment file
- Ubuntu – Difference between sh file.sh and file.sh
- Ubuntu – Grep: The asterisk (*) doesn’t always work
- Ubuntu – the difference between –init-file and –rcfile
- Ubuntu – “bash: syntax error near unexpected ‘)” in Linux Shell
- Ubuntu – Difference between three and four digit file permissions
- Ubuntu – bash script: {dir1,dir2,dir3} expansion not working as expected from variable, for picking a random file
Best Answer
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
apple
contains no such characters.But consider another example:
grep apple tree file
will search for the wordapple
in the filestree
andfile
, whereasgrep "apple tree" file
will search the wordapple tree
in the filefile
. The quotation marks tell bash, that the word space in"apple tree"
does not start a new parameter but shall be part of the current parameter.grep apple\ tree file
would produce the same result, because\
tells bash to disregard the special meaning of the following character and treat it literally.