On Aug 9, 2014, at 11:16 AM, Andreas Schwab <sch...@linux-m68k.org> wrote:
> Steve Simmons <s...@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 $? }