bug-bash
[Top][All Lists]
Advanced

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

Re: Feature request - ganged file test switches


From: Steve Simmons
Subject: Re: Feature request - ganged file test switches
Date: Sat, 9 Aug 2014 14:29:36 -0400

On Aug 9, 2014, at 11:16 AM, Andreas Schwab <schwab@linux-m68k.org> wrote:

> Steve Simmons <scs@umich.edu> 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 $?
  }





reply via email to

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