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

Re: (N) defaults to whole directory listing



> On Jan 29, 2021, at 12:01 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> 
>> On 2021-01-29 7:33 a.m., Roman Perepelitsa wrote:
>> 
>> `no_such_file(N)` expands to nothing if there is no file named
>> `no_such_file` in the current directory. This is in line with the
>> zsh documentation and what everyone expects.
> 
> That's about what I I expected to hear.  zsh can't be expected to
> feed 'ls' with something that duplicates a non-existent file, it
> can only remove the non-existent file thus leaving no argument

This only happens because you're using '(N)', which you could easily
drop if it's not desirable. It often is, though, so you need to be
aware of how the rest of your code works if a glob expands to
nothing.

> thus ls must be 'ls *'.

This is false.

	% mkdir -p foo/bar{1,2} && touch foo/bar{1,2}/baz && cd foo
	% ls
	bar1	bar2
	% ls *
	bar1:
	baz

	bar2:
	baz

You might be better off avoiding this sort of thing by testing your
globs with `print` (or something similar), as Roman demonstrated.

vq




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