bug-bash
[Top][All Lists]
Advanced

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

Re: extension of file-test primitives?


From: Dethrophes
Subject: Re: extension of file-test primitives?
Date: Wed, 23 Aug 2017 15:51:09 +0200
User-agent: K-9 Mail for Android


On August 23, 2017 3:37:51 PM GMT+02:00, Chet Ramey <chet.ramey@case.edu> wrote:
>On 8/23/17 9:34 AM, Greg Wooledge wrote:
>> On Wed, Aug 23, 2017 at 04:22:09PM +0300, Pierre Gaston wrote:
>>>  testfile () {
>>>     local OPTIND=1 f=${!#}
>>>     while getopts abcdefghLkprsSuwxOGN opt;
>>>           do
>>>              case $opt in
>>>                [abcdefghLkprsSuwxOGN]) test -$opt $f  || return 1;;
>> 
>> "$f"
>> 
>>>                *)return 1;;
>>>              esac;
>>>            done
>>>  }
>>>
>>> if testfile -fx file;then.
>> 
>> Add the quotes, make opt local too, and I think we have a winner.
>This has the advantage of supporting both syntax options: a single
>option with multiple operators or a series of options, each with one
>or more operators, combined with a single operand.

Not really as it changes the meaning of 
test -f file -a -x file
Which I always understood as the correct way of doing this in the first place...

The only optimisation would be to possible cache the stat to save on system io.

-- 
Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté.



reply via email to

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