fset.icn: Program to do set operations on file specifications

June 10, 1988; Thomas R. Hicks
Requires: UNIX
See also: gcomp.icn
This file is in the public domain.
 The UNIX shell provides for the specification of filenames
using ``wildcards''.  Each wildcard specification may be
thought of as defining a set of names (that is, those that
match the specification).  Fset allows the user to apply the
set operations of intersection, union, and difference to
these filename sets. The resultant list may then be used as
an argument to other shell commands.

Fset's argument is an expression composed of legal UNIX file
specifications, parenthesis, and the following set opera-
tors:

     &&   intersection
     ++   union
     --   difference

Because characters that have special meaning to the shell
occur frequently in the arguments used for fset, it is
advisable to quote the arguments consistently.

The use of fset is illustrated by the following examples:

     fset 'g*--*.icn'

produces the list (set) of filenames for files beginning
with g, excluding those ending with .icn.

Similarly,

     fset '*'

produces all files in the current directory excluding the .
and .. files.

     fset '((*--*.icn)++c*)'
and

     fset '(*--*.icn)++c*'

produces the complement of all filenames ending with .icn in
addition to all filenames beginning with c.

     fset '(((c? && c*)))'

is a redundant, but legal, specification for all two-
character filenames that begin with c, while

     fset '.*'

produces the set of filenames for all hidden files, exclud-
ing the . and ..  files.

Limitations:

Multiple command line arguments, formed by omitting the
quotes around the file set expression, are permitted.  Their
use is limited, however, since parentheses do not get past
the shell's command-line expansion.

Almost any legal file specification will work when enclosed
in quotes except that the simple grammar that is used cannot
handle blanks adjacent to parentheses.

File names that begin or end in ``questionable'' characters
such as *, ?, +, -, and &, probably will not work.

A file specification that, when interpreted by the shell,
produces no matching filename will be placed (unchanged) in
the result.

Source code | Program Library Page | Icon Home Page