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

Re: virtual files?



On Apr 20,  2:12am, Emanuel Berg wrote:
}
} Obviously creating a normal file just to remove it
} last thing doesn't score you any hacker points...
} 
} So I think this is a good idea for you to contemplate
} incorporating in zsh!

The problem is that implementing something like this in the shell is
fairly useless, because none of the other tools that the shell might
invoke would know what to do with it.  This is why you need something
operating-system-level like FUSE (as Nikolay mentioned), which can
make the virtual object "look like" an ordinary file or descriptor to
anything using the ordinary libraries/interfaces.

Also as Nikolay sort of mentioned in passing, you can replace

    local result_file=result
    wget -q $link -O $result_file
    grep \"answer\" $result_file | ...
    rm $result_file

with

    grep \"answer\" =(wget -q $link -O -) | ...

and zsh will take care of creating/removing the temp file for you.
You can further do

    exec {result_fd}< =(wget -q $link -O -)

and now $result_fd is a descriptor holding open an unlinked file.  If
you load the zsh/system module, you can

    grep \"answer\" <&$result_fd | ...
    sysseek -u $result_id 0

If all you're wanting is to capture output in a variable, you can use
the "read" command (or use "sysread" from zsh/system).  Zsh arranges
for "read" at the tail of a pipe to execute in the current shell
(unlike most other shells that put the pipe tail in a subshell) so

    wget -q $link -O - | read -d '' result

loads the output of wget directly into $result.

There are other things you can do e.g. with the zsh/mapfile module or
the zsh/db/gdbm module (I recommend a very recent zsh if you plan to
do anything serious with the latter), but I've rambled enough.



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