[cs631apue] How *nix commands support regex ?

Jan Schaumann jschauma at stevens.edu
Sun Sep 8 16:08:46 EDT 2013


Minhui Gu <mgu1 at stevens.edu> wrote:
> It's true. I tried to printf all argv and found them already expanded in
> the output.
> Maybe we should look into a real shell source for details.

Both of these are great ideas.  I like that you considered running a
program to actually print out the arguments as the program sees them
versus what the user passes; as a result, we can make good guesses about
what the shell itself does without even looking at the source code.

We will discuss program startup in lecture 5, but understanding how argv
is processed is a good start.

Secondly, it is _always_ a good idea to look at the source code in order
to try to understand how something works.  The great thing about the
Unix world is that the source code for the overwhelming majority of the
tools we encounter is freely available, and reading this source code is
good practice.

If you do this, you will find that the language most shells today
implement is actually quite complex.  Arguments are expanded according
to a number of rules, and trying to understand all this from the source
code alone can be daunting.

To better understand the tool, you can therefore also take a look at the
formal specification; most tools we will encounter in this class will be
part of POSIX.  For the shell, review this URL:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

-Jan


More information about the cs631apue mailing list