[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell scripts.



> On Fri, Jan 15, 1999 at 11:37:23PM +1100, Shao Zhang wrote:
> > Hi,
> > 	Where can I learn how to write the shell scripts?? Is there any
> > good documentation to read??
> > 
> > 	Thx.
> > 
> > Shao.
> > 
> 
> I would recommend O'Reilly "Learning the bash Shell". 
> (http://www.ora.com) and "Beginning Linux Programming" by WROX Press 
> has one chapter on shell programming. 
>
I found this O'Reilly book useful also. 

Just a warning: DO NOT PROGRAM in csh or tcsh.
I enthusiastically did this for two years,
only to find their limitations repeatedly
I recently read a 15 page article confirming that one should program in 
sh, ksh, or bash.
Of course, all of these are backward compatible with sh,
so a book on sh would be sufficient.
Personally, I would ignore ksh because it is commercial, 
so you won't find it or easily get it on every computer.
The bash shell does have some nice extensions not found in the sh shell,
for example, it can work with vectors and of course bash is superbly 
better than sh interactively.

Here is an example horror in csh
   awk '\
      {/ras/ printf{"got it"}} \
    ' \
    file2
Notice that I had to use a backslash at the end of every line,
unlike a bash/sh shell script.
There were some other nuicances I recently had with such a script that
caused me to abandon even bothering helping someone using a csh:
he wanted me to modify his .cshrc which I abandoned after 10 hours of
attempts.
For example a csh script like the above wants to do something odd at each
carriage return and backslash; If I put all on one line, the script would 
work, but when I used backslashes for line continuation it failed to
print.
Then, a single line (not at all neat) was limited to something like
1000 characters.

You can learn a good deal by reading "man bash", 75 pages.
And also by reading others' sh/bash scripts:
   file /bin/*  /usr/bin/*    |grep shell
gives you many good scripts to learn from (look at a few lines,
not the whole script).

-- 
Jim Burt, NJ9L,		Fairfax, Virginia, USA
jameson@mnsinc.com	http://www.mnsinc.com/jameson
jameson@pressroom.com	(703) 235-5213 ext. 132  (work)

"A poor man associating with a rich man will soon be too poor 
to buy even a pair of breeches."                   --Chinese Proverb



Reply to: