8.1. grep

The general format is:

grep [options] basic regular expression [file] 

where basic regular expression can be a string.

8.1.1. Please quote me

When you supply a string in a grep command it is good form to enclose it with double quotes. Like this: "mystring". There are two reasons for this. It stops the shell from misintepreting them as something else. Secondly, you may want to search for a string that contains a couple of words, like this: "jet plane". If you don’t surround the string with quotes it will think the word ‘plane’ is a file, and you’ll get error messages about non-existent files.

You should also use double quotes when using variables, like this: grep "$MYVAR" filename, if you do not you will get no data returned.

Use single ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.