Feature request - ganged file test switches
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
Re: Feature request - ganged file test switches
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."
'declare' does not honor '-e' in command substituted assignments - a bug ?
Good day bash list - I don't understand why this emits any output : $ ( set -e; declare v=$(false); echo 'Should not get here'; ) Should not get here $ While this does not: $ ( set -e; v=$(false); echo 'Should not get here'; ) $ Shouldn't declare / typeset behave like the normal variable assignment statement wrt command substitution ? It does not seem to be documented anywhere if it is not. I'm using bash-4.3.18(1)-release , compiled from GIT under RHEL 6.4 (gcc-4.4.7) for x86_64 - I've also tested the default RHEL 6.4 bash-4.1.2(1)-release and the latest 4.3.22(1)-release with the same results. Actually , this problem seems to apply to all built-ins - $ ( set -e ; echo $(false); echo 'not ok') not ok $ I can't seem to find this behaviour documented anywhere . The same behaviour happens in posix mode . I'd appreciate an explanation as to why this behavior is not a bug . Thanks & Regards, Jason test_-e.sh Description: Bourne shell script
Re: Feature request - ganged file test switches
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: 'declare' does not honor '-e' in command substituted assignments - a bug ?
On Saturday, August 09, 2014 04:34:11 PM Jason Vas Dias wrote: > Good day bash list - > > I don't understand why this emits any output : > $ ( set -e; declare v=$(false); echo 'Should not get here'; ) > Should not get here > $ > > While this does not: > $ ( set -e; v=$(false); echo 'Should not get here'; ) > $ http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01 "If there is no command name, but the command contained a command substitution, the command shall complete with the exit status of the last command substitution performed. Otherwise, the command shall complete with a zero exit status." The declaration commands return the status of the command itself, which masks the status of assignments. To get the status, either perform the declaration and assignment separately, or use a temporary variable to store the status. For set -e the former is the only option. -- Dan Douglas