bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: Optimal shell scripting (vs. archive generated by shar -V...)


From: Bruce Korb
Subject: Re: Optimal shell scripting (vs. archive generated by shar -V...)
Date: Sun, 29 Aug 2010 10:31:26 -0700

For next release:

On Sat, Aug 28, 2010 at 10:52 PM, Paul Eggert <address@hidden> wrote:
> For this particular example I'd suggest replacing this:
>
>        test "X$1" = "X-c" && keep_file=false || keep_file=true
>
> with this:
>
>        option=$1
>
> and this:
>
>        if test -f %s && ${keep_file}; then
>
> with this:
>
>        if test "X$option" = "X-c" && test -f %s; then
>
> This is a tad simpler and will save a file access when -c is absent.

Since we're optimizing, I still think it appropriate to do the
is-the-first-arg-"-c"
test once at the beginning, using Steve Bourne's original if/then/else style:

        if test "X$1" = "X-c"
        then keep_file=''
        else keep_file=true
        fi

instead of Steve Bourne's oft-used ``x && y || z'' construct, then:

        if test -n "${keep_file}" && test -f %s
        then

This way we don't run the "true" executable in order to check the "-c"
condition.
I should probably do a "shift" where the "-c" is recognized, too.  Another day.
How many micro (nano?) seconds have we saved, for all those unshars that
get run all the time? :)  Cheers - Bruce



reply via email to

[Prev in Thread] Current Thread [Next in Thread]