Re: Need help correcting this Bash function

From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 10/09/04


Date: Sat, 09 Oct 2004 09:07:34 -0500


Tavis Ormandy wrote:
> On 2004-10-09, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>
>>>Re-read the thread, I was asking why is it necessary to add extra code
>>
>> Who said anything about adding extra code?
>
>
> What do you think we are discussing here?

He appears to think, as I do, that we're discussing whether or not to
use bash-sepcific constructs when the equivalent generally-available
constructs could be used for about the same amount of code and
efficiency. If that's not what's being discussed, please enlighten us!

>
>>>so that some antiquated implementations don't get confused in some rare
>>>situation that is never going to happen anyway, as he's WRITING A BASH
>>>SCRIPT.
>>
>> Why is it better to write a bash script than a script that runs
>> equally well in bash, ksh, ash, and other POSIX shells?
>>
>
>
> Stop. Read Thread. Think.
>
> You seem to think I'm advocating non-portability. I'm saying why should
> exta code be added to my conditions to support antiquated, broken
> shells? _especially_ as this script is a bash script.

Because there are plenty of people out there running ksh88 and other
older shells. I use ksh88 because I often have to run scripts on
machines that don't have bash or other more recent shells installed and,
since I don't own or administer those machines, I don't want to waste my
time installing them or correcting my scripts for the brief period when
I'm using those machines.

As for the OP asking for help with a "bash script" - that doesn't mean
he wants or should only get a bash-specific solution. Plenty of people
post questions here about one tool only to be told that either:

a) they're using the tool the wrong way, or
b) the correct solution is to use a different tool.

>
>>>> Pattern matching is available with case; [[..]] is not necessary (I
>>>> have NEVER used it in a script).
>>>
>>>Well, your scripts must be needlessly complex and long.
>>
>> No, they are usually not any longer than a less portable script.
>
>
> Well then, you're lucky that you only ever have to do simple operations.

I very much doubt that's the case, but I suspect that most people would
use awk or perl for most complex operations anyway.

<snip>
> So...what is your point?
>
> a) Everyone should write 100% POSIX sh compliant code.
> b) Everyone should write 100% POSIX sh compliant code, unless it's easier not to.

I believe it's:

c) Everyone should write 100% POSIX sh compliant code, unless it's
significantly beneficial not to.

I do use gawk instead of old awk. That means I couldn't run my awk
scripts on some of those older machines I mentioned BUT there's such a
huge difference in capabilities between gawk and old awk that it's worth
it in that case and I never actually have had to use a gawk script on
one of the older machines anyway since I could just ship the data files
to a newer machine, run gawk, and ship the results back. This falls into
"c" above - it's significantly beneficial to use gawk over oawk so I do
it. In the shell cases we're discussing there's little or no benefit so
I can't imagine why you'd do it.

        Ed.



Relevant Pages

  • Re: Automatisierte TextVerarbeitung
    ... AWK - oder bessergesagt "awk" kam mir doch gleich irgendwie bekannt vor ... Einige kann man auch als exe fuer Windows beziehen ... Ich habe soeben ein altes mawk herausgekramt und ein mini-awk script, ... Betreff: Re: where are the binaries for GAWK? ...
    (microsoft.public.de.german.windowsxp.sonstiges)
  • Re: Editing text file
    ... I'd use gsar (general search and replace - ... or an awk of sed ... script. ... I'd actually do it with gawk: ...
    (comp.os.msdos.programmer)
  • Re: Geez - is Solaris /usr/bin/awk brain dead or what?
    ... >which you might want to test on your old script. ... gawk's --traditional option makes gawk support some of the stuff that ... The V7 awk did not. ...
    (comp.unix.solaris)
  • Re: Difference beetwen awk and gawk?
    ... I'm new to awk, I wrote a simple script using gawk, then change it to awk: ... 0602-533 Cannot find or open file afile.dat ...
    (comp.lang.awk)
  • Re: How to rewrite with awk?
    ... > I'm unfamiliar with tools such as sed & awk. ... Extract the string that matches a RE. ... This script will not only expand all the lines that say "include ... file) and not resetting ARGV(the tmp file), it then lets awk do any ...
    (comp.unix.shell)