Failglob issues

2013-09-01 Thread Nikolai Kondrashov

Hi everyone,

I'm trying to use "failglob" option in several projects of mine and noticed
the following strange behavior.

1) With both nullglob and failglob enabled it is considered an error for a
   glob not to match anything. I'd say it's more natural to not produce an
   error in this case. Otherwise a fairly useful behavior is broken, like
   glob use in "for" loop:

shopt -s nullglob failglob
for file in *.rpm; do
# Do something with the file
done

   Am I missing some other, more important consideration here? If there is
   none, could this be considered a bug and fixed?

2) Unquoted globs in associative array initializers with failglob enabled
   produce an error, although the documentation doesn't mention any use of
   globs there and with failglob disabled globs don't seem to expand to
   anything. I.e. this fails:

shopt -s failglob
declare -A A=([a]=*)

   Are globs supposed to have an effect in associative array initializers? If
   yes, what effect, and should this be documented? If not, is it possible
   that this is a bug and the above shouldn't fail?

Thank you.

Sincerely,
Nick



Re: Failglob issues

2013-09-01 Thread Chris Down
On 2013-09-01 12:45, Nikolai Kondrashov wrote:
> 1) With both nullglob and failglob enabled it is considered an error for a
>glob not to match anything. I'd say it's more natural to not produce an
>error in this case. Otherwise a fairly useful behavior is broken, like
>glob use in "for" loop:

Well... nullglob *and* failglob are pretty much at odds with each other. I'm
not sure what you expect to happen.

>Are globs supposed to have an effect in associative array initializers? If
>yes, what effect, and should this be documented? If not, is it possible
>that this is a bug and the above shouldn't fail?

This seems a bit more odd to me.

$ > foo
$ declare -A foo=([bar]=*)
$ echo "${foo[bar]}"
*
$ shopt -s nullglob
$ declare -A foo=([bar]=*)
$ echo "${foo[bar]}"

$ echo "$BASH_VERSION"
4.2.45(2)-release

That looks like a bug, maybe.


pgpjwn1bQYjKI.pgp
Description: PGP signature


Re: Failglob issues

2013-09-01 Thread Nikolai Kondrashov

On 09/01/2013 05:52 PM, Chris Down wrote:

On 2013-09-01 12:45, Nikolai Kondrashov wrote:

1) With both nullglob and failglob enabled it is considered an error for a
glob not to match anything. I'd say it's more natural to not produce an
error in this case. Otherwise a fairly useful behavior is broken, like
glob use in "for" loop:


Well... nullglob *and* failglob are pretty much at odds with each other. I'm
not sure what you expect to happen.


Ah, right, sorry, I didn't think this through.

Sincerely,
Nick



Re: Failglob issues

2013-09-01 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 9/1/13 10:52 AM, Chris Down wrote:

> This seems a bit more odd to me.
> 
> $ > foo
> $ declare -A foo=([bar]=*)
> $ echo "${foo[bar]}"
> *
> $ shopt -s nullglob
> $ declare -A foo=([bar]=*)
> $ echo "${foo[bar]}"
> 
> $ echo "$BASH_VERSION"
> 4.2.45(2)-release
> 
> That looks like a bug, maybe.

It is, and it was fixed in June, 2011.  The fix will be in bash-4.3 and is
in the devel branch now.

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/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlIj7cQACgkQu1hp8GTqdKuAvACfcMVeYDJNLwh8i/Q2AEzrVjdX
KxcAoIkhH2maCVthwAgVfMqoDTlh2hkd
=PXUf
-END PGP SIGNATURE-



Re: Failglob issues

2013-09-01 Thread Chet Ramey
On 9/1/13 5:45 AM, Nikolai Kondrashov wrote:
> Hi everyone,
> 
> I'm trying to use "failglob" option in several projects of mine and noticed
> the following strange behavior.
> 
> 1) With both nullglob and failglob enabled it is considered an error for a
>glob not to match anything. I'd say it's more natural to not produce an
>error in this case. 

nullglob and failglob are mutually exclusive, and failglob has higher
precedence.

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/