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

Re: cat as a builtin command



On Fri, Aug 29, 2014 at 09:40:29AM +0800, Izumi Natsuka wrote:
> Hello, I'm going to write a shell function that provides a basic functionality(print the content of a file or stdin) of cat[0], in order to avoid forking too many process when I call it in a loop[1]. And I have put the following in my zshrc:
> 
> cat() {
> 	if [[ $# -le 1 ]] && [[ ${1:0:1} != '-' || ${1} == '-' ]];then
> 		local file
> 		exec {file}<${1:-0}

If there is no argument to cat, this line would be

    exec {file}<0

It should be 

    exec {file}<&0

right? But I get error mesage for it:

    localhost% (){
    function> local fd
    function> exec {fd}<&0
    function> read -E -u $fd
    function> exec {fd}<&-
    function> }
    (anon):2: 0: bad file descriptor
    (anon):read:3: argument expected: -u
    (anon):4: failed to close file descriptor 0: bad file descriptor

0 isn't a good descriptor here?



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