-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: i686-pc-linux-gnu-gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' - -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' - -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/l$ uname output: Linux black 2.6.21-gentoo-r4 #1 PREEMPT Sun Jul 15 11:12:31 EDT 2007 i686 Intel(R) Pentium(R) 4 CPU 2.80GHz GenuineIntel GNU/Linux Machine Type: i686-pc-linux-gnu
Bash Version: 3.2 Patch Level: 17 Release Status: release Description: I set out to determine if a file was readable and not empty. To that end I tried combining the test flags -r and -s. I expected that syntax such as [[ -rs file ]] would either succeed, or fail with an error message. Unfortunately, while test -rs file and [ -rs file ] do error out (-rs: unary operator expected), [[ -rs file ]] happily ignores the 's', and returns true if and only if the file is readable. This is undocumented behavior. Repeat-By: In an empty directory execute the following commands: echo abc > file1 && chmod -r file1 > file2 for f in *; do [[ -rs $f ]] && echo "$f is readable and not empty" || echo "$f is not readable or is empty, or there was an error" [[ -sr $f ]] && echo "$f is not empty, and is readable" || echo "$f is empty or not readable, or there was an error" done In my opinion the most intuitive result would be for [[ -rs file ]] to act in an equivalent manner to [[ -r file && -s file ]]; however, the most consistent behavior would be to see the following output: bash: [[: -rs: unary operator expected file1 is not readable or is empty, or there was an error bash: [[: -sr: unary operator expected file1 is empty or not readable, or there was an error bash: [[: -rs: unary operator expected file2 is not readable or is empty, or there was an error bash: [[: -sr: unary operator expected file2 is empty or not readable, or there was an error -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGp4Zuj0Czk2KK35gRAg3sAJ9ArzxgzP+Zghl3GFBveJc3MDDUngCgjSWz x1m6TuCUHzRkkpjSDJp+SpE= =w6lb -----END PGP SIGNATURE----- _______________________________________________ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash