zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: virtual files?
Date: Tue, 19 Apr 2016 21:03:37 -0700	[thread overview]
Message-ID: <160419210337.ZM11236@torch.brasslantern.com> (raw)
In-Reply-To: <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.


  parent reply	other threads:[~2016-04-20  4:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-20  1:00 Emanuel Berg
2016-04-20  1:27 ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-04-20  2:12   ` Emanuel Berg
2016-04-20  2:31     ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-04-20  4:03     ` Bart Schaefer [this message]
2016-04-20  6:06       ` Emanuel Berg
2016-04-21 22:14       ` Emanuel Berg
2016-04-22  1:08         ` Bart Schaefer
2016-04-20  3:32 ` Benjamin R. Haskell
2016-04-20 20:34   ` Bart Schaefer
2016-04-22  5:26     ` Benjamin R. Haskell
2016-04-21  4:12   ` Emanuel Berg
2016-04-21  6:58     ` Bart Schaefer
2016-04-21  8:05       ` Emanuel Berg
2016-04-22  5:55     ` Benjamin R. Haskell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160419210337.ZM11236@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).