Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: setopt and alias questions



On Feb 12,  2:34pm, Sweth Chandramouli wrote:
> Subject: Re: setopt and alias questions
> On Mon, Feb 08, 1999 at 12:55:00PM -0800, Bart Schaefer wrote:
> > That won't work either (and my remark about "unless there happens to be a
> > file in the current directory" is wrong as well).  Filename generation is
> > not applied to the strings inside the [[ ... ]].  
> 
> 	are you sure about this?  the above (with -n instead of -x) works
> fine for me--or at least, the filename generation part does.

Did you try running the fx function?  Here it is again:

        function fx() {
            mkdir /tmp/x
            echo "echo hello" > /tmp/x/x
            chmod +x /tmp/x/x
            echo /tmp/x/*(x)
            [[ -n /tmp/x/*(x) ]] && echo Got nonzero string
            [[ -f /tmp/x/*(x) ]] && echo Globbed a file
            [[ -x /tmp/x/*(x) ]] && echo Globbed executable file
            [[ -x /tmp/x/x ]] && echo Found executable file
            rm -r /tmp/x
            [[ -n /tmp/x/*(x) ]] && echo Still got nonzero string
            [[ -x /tmp/x/x ]] || echo Found no executable file
        }

The output I get is:

  zagzig% fx
  /tmp/x/x
  Got nonzero string
  Found executable file
  Still got nonzero string
  Found no executable file

Note that "Globbed ..." was never output.  If I replace all the [[ ... ]]
with [ ... ] (single brackets), THEN I get

  zagzig% fx
  /tmp/x/x
  Got nonzero string
  Globbed a file
  Globbed executable file
  Found executable file
  zsh: no matches found: /tmp/x/*(x)

> 	could a flag be added to the list of glob qualifiers that says "if no
> matches are found, quietly return nothing but a non-zero exit status"?  i
> think "q" (for "quiet") is still free.

There already is such a flag; it's (N) for NULL_GLOB, which acts like:

  zagzig% setopt nullglob
  zagzig% fx
  /tmp/x/x
  Got nonzero string
  Globbed a file
  Globbed executable file
  Found executable file
  Still got nonzero string
  Found no executable file

(This again with [ ... ] but NOT with [[ ... ]].)



Messages sorted by: Reverse Date, Date, Thread, Author