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

Re: Perl like select()?



Hi!

>>>>> Zefram  writes:

> Josh Howard wrote:
>> Is there any way, in a script, to use a "Perl-like" select() to
>> associate stdout with a particular file, before the execution of the
>> rest of the script?

> 	exec > file

> permanently redirects stdout.  Any redirection can be used this way.

If you want to keep std{in,out,err}, you can also use a new descriptor.

Example:

# -*- sh -*-
local i file

file=~/.ssh/known_hosts

reply=()

[[ -r $file ]] || return

exec 5< $file

while read -u5 -A i
do
    reply=($reply $i[1])
done

exec 5<&-


-- 
  ____                 ____________________________________________________
 /____| NEMETH, ERVIN |____________________________________________________|
//	< airwin @ inf.bme.hu >		http://www.inf.bme.hu/~airwin
||
||	"Nonsense.  All you have to do is say 'Engage'"
||					-- Patrick Stewart about warp theory



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