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

Re: possible bug in zsh - stderr not redirected if unsatisfied wildcard



On Tue, Apr 8, 2025 at 1:04 AM Ross Boulet <rossb@xxxxxxxxx> wrote:
>
> I believe I have found a bug in zsh. If the command contains an unmatched wildcard, the error message does not get redirected as it should.
>
> Cinsider the following interaction:
>
>
>
> cartman2% mkdir mydir
>
> cartman2% cd mydir
>
> cartman2% touch a b
>
> cartman2% ls ? >stdout1 2>stderr1
>
> cartman2% ls -1
>
> a
>
> b
>
> stderr1
>
> stdout1
>
>
>
> All above is expected behavior
>
>
>
> cartman2% ls ?? >stdout2 2>stderr2
>
> zsh: no matches found: ??    ß error not redirected, stdout2 and stderr2 not created
>
> cartman2% ls -1
>
> a
>
> b
>
> stderr1
>
> stdout1
>
> cartman2%

You can do this:
% { ls ?? } >stdout2 2>stderr2
but note that glob errors are still fatal and will abort the line / script.

If you also want to avoid that, you can do:
% { ls ?? } always { TRY_BLOCK_ERROR=0 } >foo 2>bar; echo hi
hi

-- 
Mikael Magnusson




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