echo and grep
Learn to enhance the grep command usage using glob patterns. Also, know about the echo command.
We'll cover the following...
There is an option to check how the Bash expands a glob pattern. Use the echo
command for that. Below are echo
calls for checking the patterns:
echo *
echo ~/*
echo /*
The first one lists files in the current directory. The second and third command does the same for the home directory and the root directory, respectively.
Run the commands discussed in this lesson in the terminal below.
Don’t enclose search patterns in double quotes. Below is an example of the wrong command:
grep "free software" "*"
Quotes prevent the Bash expansion. Therefore, Bash does not insert the file names to the command but passes the asterisk to the grep
utility. The utility cannot handle the glob pattern properly, like find
does. So, we’ll get an error as shown in the following ...