SHELL scripts..... HOW TO START LEARN????

Mark Terribile materribile at yahoo.com
Sun Sep 14 03:28:06 PDT 2003


Denis,

> Do you happen to know where is some helpful
> information about SHELL
> programming???

Others have posted some fine references; I'd like to
belabor you with a piece of experience:

     There is a difference between writing shell
     scripts and writing shell programs.

 o A script is a series of commands as you might enter
   them at the keyboard.

 o A program is a sequence of commands that are
   composed with the same care that one would (or
   should) employ when programming in other
   languages; care regarding the ability of someone
   else to read and understand the program; care
   regarding one's own ability to read and understand
   it six months, or sixty months, later; care that
   inputs are validated and variables are used
   consistently, etc.

Since shell programs invoke shell commands and
pipelines, and since commands and pipelines of
commands all use different argument syntaxes, it's
very important to make sure that the person trying to
read the overall flow doesn't get lost in the minutia.

This requires that program organization be at least
as good as the organization of a C or C++ program ten
times the size of the shell program.  Keep related
computations together in groups, just as you put
related sentences in order in a paragraph.

It also requires more attention to naming what you
are doing.  If you have a pipeline constructed with
arcane commands to do subtle and magical things, put
it in a shell function and name it clearly.  (If your
shell does not support functions, switch to one that
does.  I like  ksh , but  bash  is good too.)  Use
functions freely and test them independently of each
other.  (It's easier in the shell than in most
programming languages.)

Since most shells do not support structured data,
you cannot use  structs  (or records, or classes)
to describe your data layout.  Comment your data
accurately.  This does not necessarily mean profusely.

When you use a new variable in a function scope, use
whatever the shell gives you to make sure that you
are using a local instance, and not writing over a
variable in an outer (dynamic) scope.

There's lots more, but this will get you started.

                                 Mark Terribile


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


More information about the freebsd-questions mailing list