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

Re: {fd}< and compound commands



2011-09-14 20:06:01 +0100, Peter Stephenson:
[...]
> You need to do:
> 
> local fd
> 
> {
>   exec {fd}<file
> 
>   while read; do
>     ...
>   done <&$fd
> } always {
>   exec {fd}<&-
> }
[...]

Except that if the first exec fails, that might close the wrong
fd.

Maybe:

if command exec {fd}<file; then
  {
    while read <&$fd; do
      ...
    done
  } always {
    exec {fd}<&-
  }
fi

-- 
Stephane



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