1846464 Members
2579 Online
110256 Solutions
New Discussion

Shell Programming

 
SOLVED
Go to solution
Programmer
New Member

Shell Programming

Hi,

Can someone tell me the difference between metacharacters, pattern matching, wildcards, filename completion, and regular expressions...
4 REPLIES 4
Sandman!
Honored Contributor

Re: Shell Programming

Best place to start looking is the man page for regular expressions...

# man 5 regexp

best of luck!
James R. Ferguson
Acclaimed Contributor
Solution

Re: Shell Programming

Hi:

"Pattern-matching" is the science and art of matching, extracting and/or substituting text. Just as you would imagine, you are looking for a particuar pattern of characters, for instance, two digits (0-9) followed by a blank character.

"Regular expessions" are the basis for pattern-matching.

Many, many utilities and languages implement regular expresssion engines, Perl, 'awk', 'sed' and 'grep' begin among the most notable UNIX ones.

Simply speaking, metacharacters are characters that drive the regular expression engine. For instance, the caret (^) is a metacharacter that specifies the beginning of a line. A dot (".") represents any character. A plus ("+") denotes one or more repetitions of the preceeding character. The actions that metacharcters produce in regular expresssions can be turned of by escaping them with a backslash "\" character in front of them.

"Wildcard" is a term generally used with the shell to refer to certain metacharacters that have special meaning to the shell. They do not necessary have the same meaning as in a regular expression!

"Filename completion" is a shell feature whereby by typing part of a file's name and then hitting the escape key, completes a file name on the command line if what has been typed to that point can be resolved into a unique name.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Shell Programming

Shalom Programmer,

filename completion is when you hit a certain key sequence, while typing a partial filename. If there are no other possibilities then the filename completes. If there are multiple possibilities it will complete up to the point they have in common

in a set -o vi/POSIX environment the squence is escape escape.

Under Linux its tab tab. A third tab under Linux will list filenames.

This is a form of pattern matching.

A wildcard is thus.

ls he*.txt

ls all files starting with he and having any other characters and a .txt on the end.

The wildcard is the asterisk. A question mark can serve as well.

Lets say we have three files.

file01.txt
file02.txt
file03.txt

ls file??.txt

Will list all files with the name file wild card wildcard .txt

Hopefully these examples will help because my fingers are tired.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Programmer
New Member

Re: Shell Programming

Thanks Steven...