Re: Weirdest shell behavior ever...

On 2010-09-01, Ed Morton <mortonspam@xxxxxxxxx> wrote:
No, do not do it in C. That'd be even worse that doing it in shell.

I'm not totally sure of that. While it's certainly not the friendliest
string processing language ever, I have a LOT of control over the inputs,
allowing me to make things easier -- and I have 100% guaranteed portability
then. (For my purposes, anyway.)

Use perl if
that's your only other choice, but you're using "tr", "wc", etc. in your script
and those are commands that come with every UNIX and you call from shell just
like awk is a command that comes with every UNIX and you call from shell, so I'd
think you could just as legitimately use awk as you could tr, etc. and stay
within the intent of whoever came up with the rule about only using C, perl, and sh.

Historically, we've allowed only one-liner awk scripts -- anything over that,
and a whole lot of people suddenly have to learn awk in order to be able
to read the code. The people who do my code reviews would agree that it was
witty and clever of me to say "see, it's just a shell script that just happens
to do everything by calling awk once", then ask to see the real code I was
expecting them to review.

When I originally wrote it, shell seemed like a good choice because it was
all simple string processing with very few special cases. The special
cases have shown up by bits and pieces, and now we're getting to about time
for a rework. I'm honestly not sure what I'd most like for the rework; of
the languages I know, my first choices would probably be Ruby and C, in that
order. (C, not because it's a great string processing language but because
I'm most fluent in it...) Of those acceptable for the project I need this
working in, I'm guessing perl will win, although it's gonna have to be in
a pretty stripped down subset. But that can be livable.

Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@xxxxxxxxx <-- lawsuits, religion, and funny pictures <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.