[KLUG Members] linux scripts

Bruce Smith members@kalamazoolinux.org
15 Aug 2002 16:44:09 -0400


There are two types of commands you can put into a shell script.

1)  Standard *nix commands (that live in the ..../bin directories), the
same commands that are run at the interactive command line.  They are
very useful for a variety of functions.  A lot of them are useful in
pipes for parsing output from other commands.  All of these commands
[should] have their own man page on your computer.

2)  Commands built into the shell (probably "bash" in Linux).  These
commands include a lot of logic and flow control for your script. 
Commands like "if/then/else/elif", "while", "for", "case", ...
These commands do NOT have their own man page, but are ALL included in
the man page for bash (or whatever shell you're using).

The man page for bash is good reference for these (#2) commands, but the
bash man page is HUGE, things are hard to find, and is NOT recommended
for someone just starting to learn scripting.  I mention it for
completeness and future reference.

To get started I recommend a good book, or a web site dedicated to
getting started with scripting (some already mentioned).  Plus examples
are priceless, and a standard Linux install is full of shell scripts the
system uses.

BTW, shell scripts are almost as powerful as a full blown programming
language, a giant step above DOS .bat files.  I've written some scripts
that probably should have been done in "C" for speed, but it's amazing
the power you have in the shell script.  I've been writing scripts for
many years (as I'm sure many other people on the KLUG lists have), so
feel free to post specific questions, either here or on the novice list.

I did a presentation a long time ago on introduction to shell scripting.
How many people are interested in seeing it again at a KLUG meeting?


> In Dos/Win I could write a simple command line script with a bit of programming,
> name the extension .bat and execute it whenever I want.
> 
> In Linux it appears I can do the same.  Just write command lines, save as text
> and make it executable.
> 
> Now, I want to have some functionality in the code (if this, do that, else,
> on_error, ...).  I'm thinking that in Linix, scripts can be handled by different
> processors by using the #path_to_shell as the first line.  But, that's as far as
> I know.
> 
> Is my "shell" thinking correct?
> 
> What would be the best way to add simple functionality to scripts?
> 
> Where could I find info on the proper syntax for the appropriate shell?


--------------------------------------------
Bruce Smith                bruce@armintl.com
System Administrator / Network Administrator
Armstrong International, Inc.
Three Rivers, Michigan  49093  USA
http://www.armstrong-intl.com/
--------------------------------------------