Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: virtual files?
- X-seq: zsh-users 21460
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: virtual files?
- Date: Tue, 19 Apr 2016 21:03:37 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=5KM7k06nS6cHcnJmj2q/BUY5+bxUOEWSsVA7VNvsbms=; b=neTPGWX0rg+hh3d5EsLIv7KkMrWyP3lfh5QGr9Drxum7ZlO0X3gG2E5rU2YM9EuG7Q IhLCArXjWO2jjTd/OMJn3CWTsY9vSUwvI0QisT8ZcBUT5gd/7toPpXrCQySSlfZ83SDi fhHABqDLkQgDhewJD6s8cr4vOlNpOlCEO1ZGlWKoLP8LthmfHGTpJJIEwNlDTezFLg5E jpd98ZmlZWSCu873ReAVcDv5Kj2v7RoYQrT7rnoMkrc6hZiAQCJ/0YOXbDumzxaw0jPK doIFnEgj3hKO4WZSNn+HuPUjhr6fICYmuZen1NXk0U1ybshmCmLYsPFSEh2PgN5d/ZSG qleg==
- In-reply-to: <87zispqb9m.fsf@student.uu.se>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <8760vdrt5y.fsf@student.uu.se> <1302351461115632@web4o.yandex.ru> <87zispqb9m.fsf@student.uu.se>
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