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

Re: Bash usage: was implicit linkage



Hi Steve:
I agree that shell scripts are simplistic and not meant for fancy programs although it could be done, just not productive. But the nice thing is shell scripting is simplistic easy to learn and understand. Sure beats the days when I wrote code in Assembler, Cobol, Fortran, PL1, RPG, Easytrieve, Focus.

Those days are gone with the likes of Perl, Pascal, C++, etc.
Peter
On 11/10/14 09:40 PM, Steve Litt wrote:
On Sat, 11 Oct 2014 19:05:19 -0400
Doug <dmcgarrett@optonline.net> wrote:

On 10/11/2014 05:28 PM, Steve Litt wrote:
On Sat, 11 Oct 2014 21:21:14 +0300
Daemontools runscripts are incredibly simple shellscripts, that I'm
sure you could write no sweat except in very wierd edge cases.
Here's my run script for my home-grown cron substitute:

======================================================
#!/bin/sh

####### DON'T START littcrond UNTIL THE NETWORK'S UP #######
pingaddr=8.8.8.8
pingaddr=192.168.100.96
echo littcrond checking network 1>&2
while ! ping -q -c1 $pingaddr > /dev/null; do
    sleep 1
    echo littcrond REchecking network 1>&2
done

####### RUN THE DAEMON #######
exec envuidgid slitt envdir ./env setuidgid slitt  \
    /d/at/python/littcron/littcron.py \
    /d/at/python/littcron/crontab
======================================================

The last three lines are really one line that wordwraps in email.
If I hadn't checked for the network being up, this would have been
a two line shellscript. I've known you (online) for several months,
and although we sometimes disagree, I know you're pretty smart, so
I'm positive you could have written this shellscript without
breaking a sweat.


/snip/

I've been using Linux seriously for about five years, altho I diddled
around with it a bit earlier. About the time I started seriously using
it, I took a course in Linux at the local community college, of which
perhaps a third was devoted to scripting. Quite some time earlier, I
had taken a course in Pascal, which I did very well in, and I actually
wrote some useful code in that language for my job as an engineer.
Prior to that, I used and wrote a lot of stuff in BASIC.
Getting back to my Linux class, I received a B+. I don't know how much
code I could have actually written when class was over, since one
needs to know a lot more about system commands. At any rate, it's
been about five years, and I could not now write the script you use
to illustrate this message, and I'm not really sure I can read it!

BASH scripts are written in perfectly logical code, quite similar, in
fact, to Pascal. The problem is that they don't have the advantage
of normal language; they rely on all sorts of abbreviations instead
of the English words that more popular programming languages like
Pascal, C, Python, and BASIC use. It's been probably 25 years
since I wrote anything in Pascal or BASIC, but with about 30 minutes
of reference-book research, I think I could go back and do it now.
I can't imagine that to be true with BASH scripting.

Just call me dufus.

--doug
Hi Doug,

You're absolutely right.

 From my viewpoint, shellscripts were never intended to be big, huge
programs. To me, they just glue together commands, and have a few
rudimentary branching and looping constructs. Their loops are
incredibly slow, you'd *never* do an inner loop in Bash.

To me, if something involves you doing your own logic rather than
calling other executables to do it, then Python, C, or some other "real"
language is the way to do it.

So yes, sysvinit startup scripts are on the far edge of what Bash
should be used for. I'd say most daemontools run scripts are under 20
lines of code, so you'll be able to re-figure them, in a few minutes,
six months from now.

Now that I've said that, you can accomplish some pretty incredible
things by gluing a few commands together. I wrote the better half of a
http log evaluation program using a shellscript gluing together grep,
cut, and awk, and piped the remainder (which was a much smaller data
set than what went in) to a Python program or something like that.

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance




Reply to: