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

Why does >&- produce an error message when connected to a builtin? (was Re: (N) defaults to whole directory listing)



On Fri, Jan 29, 2021 at 9:05 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Fri, Jan 29, 2021 at 7:33 AM Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> >
> >   ( ls -1 no_such_file(#q) ) 2>/dev/null
>
> That can be done without a subshell:
>
> { ls no_such_file(#q) } 2>&-

Why does >&- produce an error message when connected to a builtin,
rather than an external command?

% print -qqq
print: bad option: -q
% git -qqq
unknown option: -qqq
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
% print -qqq 2>&-
zsh: write error
% git -qqq 2>&-
%

And for the cases below, why does it produce an error message for the
former, but not for the latter?

% { print -qqq } 2>&-
zsh: write error
% { print no_such_file(#q); print -qqq } 2>&-
%

Is this an intended or unintended difference?




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