Scripting problem

Warren Block wblock at
Wed Oct 11 23:02:01 UTC 2017

On Mon, 9 Oct 2017, Paul Pathiakis wrote:

>> Quoting is sh's biggest weakness. Well, that and lack of basic data
>> structures, and the weak logical structures, and so on.
> ### Well, yes and no. I consider it both a strength and a weakness. I find sh to be exactly what I think of a scripting language to be... glue. I don't
> expect to write a fully versed program in sh. I wouldn't be using sh for that. I find sh to be that 'tool' to use when I want to call other tools and
> utilities. (sed, awk, tr, etc)
> ### I think people have gone way too far in creating 'scripting' languages that are more programming languages than scripting.... Personally, I tried
> learning PERL which tries to be everything to regex. The problem? Lack of coherence... "I can do this 5 different ways in PERL" Is that supposed to be a
> good thing when all five seem to execute at different speeds, using different resources, etc? (apologies to Larry Wall and the rest)

The multiple domains that are utterly different are not just in Perl. 
In sh, you can use sed and awk, which have very little overlap.  In 
fact, you pretty much have to use sed *and* awk, because each is not 
quite powerful enough to do particular jobs.  Or use Perl, 
which is a superset of both.

The trouble with sh is that it is so weak that it takes a lot of code to 
accomplish anything. That comes back to haunt the programmer in the long 
term, because simpler, shorter programs that use more powerful 
constructs are much easier to maintain.

Perl is much-maligned, but every time I rewrite a shell script in Perl 
it gets shorter and easier to maintain.  Or longer and more powerful. 
Python and Ruby are similar.

>> Someone once said that if a script is longer than twenty lines or so, 
>> it probably ought to be done in a real scripting langugage. That was 
>> me, but Stephen Bourne has also said it. Yes, that Stephen Bourne.
> ### I'll go off a little on this with kind of a corollary.... No sh script should be more than 20 lines, however, I typically will call shell scripts from
> other scripts. But I do agree, if you want to program, use a programming language. (IMHO, C is still the best, most powerful language around but, again,
> read a book, talk to the people who are in the know - My 'C' guru is a guy who has written code that utterly shocked me in its elegance, execution, and
> simplicity - and the occasional "You can do something like that in C?" thoughts running through my head.)

The distinction between programming and "scripting" has always been 
artificial to me.  You write a series of instructions for a computer, 
that's a program.  Give me powerful tools, I'm not interested in doing 
it the hard way to build character.  I have enough character. What I 
want back is the time I spend trying to fix sh scripts.

More information about the freebsd-questions mailing list