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

Re: $(<nofile) doesn't set $? to non-zero



2018-03-14 10:32:54 +0000, Stephane Chazelas:
[...]
> Note that all shells are silent and return 0 for var=$(</etc)
> var=$(</dev/mem) or any file that can be opened but not read
> successfully, which IMO is not ideal.
[...]

In zsh, one can use $ERRNO though:

$ zsh -c 'zmodload zsh/system; ERRNO=0; var=$(</); echo $? $ERRNO; syserror'
0 21
Is a directory
$ zsh -c 'zmodload zsh/system; ERRNO=0; var=$(<file); echo $? $ERRNO; syserror'
zsh:1: no such file or directory: file
0 2
No such file or directory

(same for $mapfile[file] which is silent on errors).

-- 
Stephane



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