Re: Feature request - ganged file test switches

2014-08-13 Thread Steve Simmons
On Aug 13, 2014, at 2:31 PM, Ken Irving  wrote:

> I like the idea, but switch negation would need to be supported, and
> I don't think that's been covered sufficiently.  Using ! as a switch
> modifier might be possible, and I like it, but would then also apply to
> single filetest switches, e.g., -!e foo would be the same as ! -e foo.
> Maybe that's possible, but it seems a fairly major addition to the syntax.

Agree on all.


> I'm a little confused about the 'before' example:
> 
>if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .
> 
> I thought that && could be used reliably within the [[ ]] construct,
> including short-circuiting the tests, so this could be:
> 
>if [[ -d foo && -r foo && -x foo ]] ; then . . .
> 
> I don't see how the bundled switces could be ambiguous, so must be 
> missing something.

Both forms work, which I didn't expect. Learn something new every day; thanks.




Re: Feature request - ganged file test switches

2014-08-13 Thread Ken Irving
On Wed, Aug 13, 2014 at 12:16:52PM -0400, Steve Simmons wrote:
> 
> On Aug 12, 2014, at 4:36 PM, Chet Ramey  wrote:
> 
> > On 8/9/14, 7:07 AM, Steve Simmons wrote:
> > 
> >> It would be nice to have ganged file test switches. As an example, to test 
> >> that a directory exists and is properly accessible one could do
> >> 
> >>  if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .
> >> 
> >> but
> >> 
> >>  if [[ -drx foo ]] ; then . . .
> >> 
> >> is a lot easier.
> > 
> > Sure, but it's only syntactic sugar.
> 
> Knew that going in :-). Other discussion points out how limited it is;
> I'm perfectly happy pulling back. My thoughts on how to do this more
> flexibly boil down to the capabilities gnu find has w/r/t file types
> and modes. Unfortunately we have a few systems which lack gnu find
> and are "vendor supported appliances" (eyeroll) and we're unable to
> add new software beyond simple scripts. Which also means that any new
> bash feature would probably be unavailable for years, so it's not like
> this is a big loss.
>
> If others have no interest in this syntactic sugar I see little point
> to adding it; a broader and more flexible solution is just to use find
> as above.

I like the idea, but switch negation would need to be supported, and
I don't think that's been covered sufficiently.  Using ! as a switch
modifier might be possible, and I like it, but would then also apply to
single filetest switches, e.g., -!e foo would be the same as ! -e foo.
Maybe that's possible, but it seems a fairly major addition to the syntax.

Using caps for switch negation is pretty common, but the filetest switches
already use some uppercase values, so I don't think that's possible in
this case.

I'm a little confused about the 'before' example:

if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .

I thought that && could be used reliably within the [[ ]] construct,
including short-circuiting the tests, so this could be:

if [[ -d foo && -r foo && -x foo ]] ; then . . .

I don't see how the bundled switces could be ambiguous, so must be 
missing something.

Ken



Re: Feature request - ganged file test switches

2014-08-13 Thread Steve Simmons

On Aug 12, 2014, at 4:36 PM, Chet Ramey  wrote:

> On 8/9/14, 7:07 AM, Steve Simmons wrote:
> 
>> It would be nice to have ganged file test switches. As an example, to test 
>> that a directory exists and is properly accessible one could do
>> 
>>  if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .
>> 
>> but
>> 
>>  if [[ -drx foo ]] ; then . . .
>> 
>> is a lot easier.
> 
> Sure, but it's only syntactic sugar.

Knew that going in :-). Other discussion points out how limited it is; I'm 
perfectly happy pulling back. My thoughts on how to do this more flexibly boil 
down to the capabilities gnu find has w/r/t file types and modes. Unfortunately 
we have a few systems which lack gnu find and are "vendor supported appliances" 
(eyeroll) and we're unable to add new software beyond simple scripts. Which 
also means that any new bash feature would probably be unavailable for years, 
so it's not like this is a big loss.

If others have no interest in this syntactic sugar I see little point to adding 
it; a broader and more flexible solution is just to use find as above.


Re: Feature request - ganged file test switches

2014-08-12 Thread Chet Ramey
On 8/9/14, 7:07 AM, Steve Simmons wrote:
> Advance apologies if this has already been discussed and rejected.

It hasn't.

> It would be nice to have ganged file test switches. As an example, to test 
> that a directory exists and is properly accessible one could do
> 
>   if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .
> 
> but
> 
>   if [[ -drx foo ]] ; then . . .
> 
> is a lot easier.

Sure, but it's only syntactic sugar.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Feature request - ganged file test switches

2014-08-09 Thread Steve Simmons
On Aug 9, 2014, at 11:16 AM, Andreas Schwab  wrote:

> Steve Simmons  writes:
> 
>> Advance apologies if this has already been discussed and rejected.
>> 
>> It would be nice to have ganged file test switches. As an example, to test 
>> that a directory exists and is properly accessible one could do
>> 
>>  if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .
>> 
>> but
>> 
>>  if [[ -drx foo ]] ; then . . .
>> 
>> is a lot easier.
> 
> But it is ambigous.  Does it mean adjuntion or conjunction?

Good point. I'd intended conjunction. And then of course, there's the negation 
issue. Something like 
  [[ -dw!x foo ]]
for "writable directory but not executable" is terse and quick to write, but 
that way probably lies madness. Nope, I'm sticking to it being equiv to the 
larger expression above. As a possible alternative syntax with more 
flexibility, maybe
  [[ -d -a ( -r -o ! -x ) foo ]]
which is true for a directory that's either readable or not executable. What 
I'm looking for is a way to do a lot of file tests out of a single stat() call 
with a clear, simple, and terse syntax. I'm tired of writing shell functions 
like
  is_writable_dir() {
  [[ -d $1 ]] && [[ -w $1 ]]
  return $?
  }





Re: Feature request - ganged file test switches

2014-08-09 Thread Andreas Schwab
Steve Simmons  writes:

> Advance apologies if this has already been discussed and rejected.
>
> It would be nice to have ganged file test switches. As an example, to test 
> that a directory exists and is properly accessible one could do
>
>   if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .
>
> but
>
>   if [[ -drx foo ]] ; then . . .
>
> is a lot easier.

But it is ambigous.  Does it mean adjuntion or conjunction?

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Feature request - ganged file test switches

2014-08-09 Thread Steve Simmons
Advance apologies if this has already been discussed and rejected.

It would be nice to have ganged file test switches. As an example, to test that 
a directory exists and is properly accessible one could do

  if [[ -d foo ]] && [[ -r foo ]] && [[ -x foo ]] ; then . . .

but

  if [[ -drx foo ]] ; then . . .

is a lot easier.

Best,

Steve