[comp.unix.questions] Problems that need counting

martin@mwtech.UUCP (Martin Weitzel) (03/21/90)

At this time there goes a small discussion about the methods of "counting"
in shell scripts. IMHO using (much) arithmetic in shell scripts is an
indication that one should think about some other way to do the job.

Before you flame me or mail me large scripts to show how essential
counting is in *your* (Bourne) shell application please note: I don't
doubt that there *are* situations for counting and other arithmetic
operations in shell scripts. I only claim that there are fewer situations
as you think, esp. if you were trained to work with an "ordinary"
programming language, before you made the step to the shell.

If you want, please post (or mail me, I'll sumarize) a short example
of a shell script, which
	a) has a strict need to do "counting" (or other heavy use
	   of arithmetic)
	b) could not easily split off (name the reasons!) the
	   arithmetic work and leave it to some other tool like
	   "awk", "bc" ... (Poor performance may be one such reason!)
In short, the example should show that a shell 'builtin' for arithmetic
were a *real* benefit for that problem. (What I don't want to see
are programs to calculate the first 100 primes, print a table of sine-
and cosine values etc., because that would not be typically done in a
job control language like the shell.)

Please do *not* post or mail the whole script! Cut out only the
essential parts or only describe the problem.
-- 
Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83

maart@cs.vu.nl (Maarten Litmaath) (03/22/90)

In article <686@mwtech.UUCP>,
	martin@mwtech.UUCP (Martin Weitzel) writes:
)... I don't
)doubt that there *are* situations for counting and other arithmetic
)operations in shell scripts. I only claim that there are fewer situations
)as you think, esp. if you were trained to work with an "ordinary"
)programming language, before you made the step to the shell.

Whatever, shell arithmetic isn't that difficult to implement, it doesn't
take that much code, and it increases the elegance of scripts.  It's rather
ridiculous I have to refer to a gross construct like the following to do
some simple increment:

	i=`expr $i + 1`

I'm not solving some integral equation, you know!
The fact that `expr' maybe a built-in in modern sh versions doesn't change
my point.

It's just the whole case for shell scripts: why does one use them?
Answer: because it's ridiculous to write a C program for every little
problem!  And at that they're portable (without the fuss of recompiling).
--
 1) Will 4.5BSD have wait5()?         |Maarten Litmaath @ VU Amsterdam:
 2) Sleep(3) should be sleep(2) again.|maart@cs.vu.nl, uunet!mcsun!botter!maart