Re: Need help correcting this Bash function

From: Tavis Ormandy (taviso_at_sdf.lonestar.org)
Date: 10/09/04


Date: 9 Oct 2004 13:40:47 GMT

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?

>> 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.

>>> 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 am putting together a collection of scripts that will run in
> any POSIX shell. When there is a shorter or faster way using a
> bash or ksh93 feature, I add that as an alternative. You'd be
> surprised how few there are.

Why do you think these features were added?

David Korn was feeling bored one day?

Because people wanted them.

> There are some things I would not try to do in anything other
> than bash (or, perhaps, ksh93). For example, in another thread
> (pointing best size directories...) I posted a script that is
> bash specific, because it is more efficient.

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.

>> But if the satisfaction that should you distribute your script to
>> anyone, the 0.001% of people out there running
>> foosh-0.892-patchlevel42_rc3 on a VAX that hasnt been updated in 30
>> years makes up for that, good for you.
>
> If it gives you satisfaction to write code that will be hard to
> use an another system when you could have written code that
> would run there without any loss of efficiency, good for you.

Yes, hard to use on another system that has been trapped in stasis for
20 years.

It gives me satisfaction to take advantage of all the new features
designed to make my scripts more powerful, efficient, and easier to
write.

>> Why do you think these new features are added? to force users into an
>> upgrade path? No, beacuse they are useful.
>
> Why is [[...]] any better than case ... esac for the same
> functionality?

* the code is already an if construction, rewriting it as a case
  statement requires additional effort.
* [[..]] allows for future expansion that case cannot provide.

> Why is [[...]] any better than [...] for the same functionality?
>

If you think [..] provides the same functionality as [[..]], you need to
check the documentation.

>>>> You're taking this out of context, I'm all for portability, but he's
>>>> writing a bash script, why not use the features that every modern shell
>>>> written in the last decade has and could genuinely be useful here?
>>>
>>> I do use those which are POSIX-compliant and common to those
>>> shells. I don't use those which are limited to one or two shells
>>> unless it makes a significant difference to the task at hand
>>> because as I said before, I might want to use the script on a
>>> machine which doesn't have bash, and on which I cannot install it.

[[..]] isn't bash specific, all modern shells have it. It's a ksh93
feature, I believe.

>> Very true, you might also fall through a time portal and need to run it
>> in 1976. Now that you mention it, I'm pretty outraged people are using
>> perl5 features in their perl scripts, what if someone out there is still
>> on perl4?!?!??!
>
> I'm outraged that people are using any version of perl! ;)
>
>> won't somebody, please, think of the children!
>
> ????

It's a quote from the simpsons, everytime there is a moral issue in the
town, one of the characters always says this. It was a joke :)

> Why use a bus if a compact car will do the job?

You mean, why use a ferrari when a bicycle will do the job?

> When did you last use it in a situation where case would not have
> been just as efficient?

Today.

-- 
-------------------------------------
taviso@sdf.lonestar.org | finger me for my gpg key.
-------------------------------------------------------


Relevant Pages

  • Re: bash: WHY???
    ... IMHO bash 2.05+ is the most usable interactive shell as it has ... OK - but call it a bash script, ... default in sh using sh features. ...
    (comp.unix.solaris)
  • Re: Need help correcting this Bash function
    ... >> The set of constructions that are valid in all reasonably ... > situation that is never going to happen anyway, as he's WRITING A BASH ... equally well in bash, ksh, ash, and other POSIX shells? ... >> have NEVER used it in a script). ...
    (comp.unix.shell)
  • Re: #!/usr/bin/env bash
    ... I work a few systems which have bash in different locations by default ... when I write a script for one OS move it on to another I end up having ... env looks up bash in the list of directories specified by the ... Do you really need bash specific features, ...
    (comp.unix.shell)
  • Re: Bash calls TCL, TCL calls Bash, 2nd Bash never reads input
    ... :Which is the correct term to use? ... If the script uses bash specific features, ...
    (comp.os.linux.misc)
  • Re: Bash calls TCL, TCL calls Bash, 2nd Bash never reads input
    ... :Which is the correct term to use? ... If the script uses bash specific features, ...
    (comp.unix.misc)