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:
[...]
> {
>   exec {fd}<file
> 
>   while read; do
>     ...
>   done <&$fd
> } always {
>   exec {fd}<&-
> }

Thanks Peter,

Why the "always" here?

> (although in this particular case there's nothing to stop you doing
> 
> while read var; do
>   ...
> done <file
> 
> but I presume you have something more complicated in mind.)
[...]

Well, using fd 0 here is dangerous as you never know if commands
in the loop will attempt to read from it (think of ssh without -n
for instance), or you may actually want them to read from (the
original) stdin.

-- 
Stephane



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