About Me

ఏదైనా సబ్జెక్టు లో కి డీప్ గా దిగకుంటే నాకు నిద్ర పట్టదు

Thursday, June 21, 2007


This is in Draft Version: it will be modified and beautified later : thanks for patience:
There are two kinds of Pattern Matching.
1.File Name matching pattern
2.File content Matching pattern(Regular expressions)

File matching patterns are different from
regular expression patterns.
while the former is interpreted by shell to search for specific files
the latter is interpreted by the command to search for the lines inside
a file.,

When you press the enter button after typing the command with the arguments etc.,
the shell has something to do before calling the command finally..
That is it has to do Shell interpreting & expansion

Shell interpeting & expansion:

The power of shell lies in interpreting certain meta characters.
When the shell starts parsing the command line,
and if it encounters any meta characters ,it searches for the files
with the specific patterns in the pwd, and if any files are found
then the list of matched files(space separated) is substitued
in the command line..

Now Shell will call the final command..


Now not only shell there are certain built in commands
which can do special character interpretation..
This is the power of unix, but this is the foundation stone for confusion..

We have to pass the special characters via arguments to the command..
and the special characters to be interpreted by shell also should be
passed to the shell via the command line..

Whats the confusion here?

the shell and command may have the same meta characters...
for eg: * is interpreted differently by shell and command?

Then wats the problem?

if you intended for a meta character like * to be interpreted by
the command ,there is a chance that it might be interpreted by shell
and substituted by the shell if any matches occur.

because shell interpretation precedes the command interpretation.,
that is the regular expression pattern that you type on the command line
is parsed by the shell
so there is a danger because the regular expression meta
characters are interpreted by shell to do its file matching..

So we have to be extra cautious for such things?

Escaping the meta characters,ie., instruct the shell not to interpret
such characters..
Way1: back slash
way2: double quotes
way3:single quotes

No comments: