zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: set -F kills read -t
Date: Wed, 19 Mar 2014 10:08:44 -0700	[thread overview]
Message-ID: <5329CF1C.5020109@eastlink.ca> (raw)
In-Reply-To: <140318233741.ZM3708@torch.brasslantern.com>

[-- Attachment #1: Type: text/plain, Size: 3013 bytes --]

On 03/18/2014 11:37 PM, Bart Schaefer wrote:
>      cat /dev/null | func
>
> There will be no output from cat, so as seen by [the commands in the
> definition of] func, there's a pipe, but there is no input.
Yabut 'cat' still returns, so I'd use that as the terminator.

      echo "" | func

... would 'know' that echo is 'finished' and that's that. Can't one 
process know that
another process is finished? Anyway it doesn't matter, Jan's solution is 
crisp,
understandable, robust and has no ifs, buts or maybes. As you said, this 
asynchronous
stuff is bedrock to shell and it ain't going to change, I hafta get used 
to it.
>
> Shell functions are little more than names for the set of commands
> inside them; it's nonsensical to say that "func should politely wait".
> What will politely wait (or not) is the first command inside func
> that attempts to read standard input.  If there is no such command,
> nothing waits.
Of course. One can't presume that the function has some behaviours apart 
from
the behaviours of it's contents. But in this case we're referring to 
'read' and  I
had speculated that 'read' might be able to have the option of being 
asked to wait
for some previous command to finish. Come to think of it, what it would 
do is
take Jan's code and more or less bundle that into an option to 'read'. 
Nevermind:

     if [ ! -t 0 ]; then read input; fi

... isn't exactly hard to type. I yield the point.
>
> It's not actually the case that $@ "soaks up" anything.
>
> and then grep, noting that it has only a pattern and no file name, reads
> from standard input just like it always does.
I see. Thanks for pointing that out, I was about to replace ignorance 
with false understanding.
I thought I was expecting this to work:

      $ y () { echo "$1, $2, $3 "; }

      $ y one two three
     one, two, three

     $ echo "one two three" | y
     , ,                                                  << :-(


So grep is doing the 'switcheroo' here--going from reading arguments, to 
reading stdin, and
the pipe is the de facto 'stdin', and piped input does NOT become 
arguments :-)

Got it.

I'm doing this sort of thing now, and I'm as happy as a clam:

    function y ()
    {
         pipeinput='(nothing in the pipe)'
         terminalinput='(nothing from the terminal)'
         if [ ! -t 0 ];  then read pipeinput; fi
         if [ -n "$1" ]; then terminalinput="$@"; fi
         echo "$pipeinput $terminalinput"
    }

    $ y "from an antique land"
    (nothing in the pipe) from an antique land

    $ echo "I met a traveller" | y
    I met a traveller (nothing from the terminal)

    $ echo "I met a traveller" | y "from an antique land"
    I met a traveller from an antique land

    $ echo "I met a traveller" | y "from an antique land" | y "\nWho
    said: \"Two vast and trunkless legs of stone"
    I met a traveller from an antique land
    Who said: "Two vast and trunkless legs of stone


...

Who could ask for more transparent code? Thanks all for your patience.

  reply	other threads:[~2014-03-19 17:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-02 14:26 implementing a control for completing filenames with a defined list of tokens Eric Smith
2013-12-02 15:58 ` Bart Schaefer
2014-03-16 14:13   ` Eric Smith
2014-03-16 19:27     ` Bart Schaefer
2014-03-16 20:13       ` Bart Schaefer
2014-03-18  3:10         ` set -F kills read -t Ray Andrews
2014-03-18  6:50           ` Bart Schaefer
2014-03-18 16:22             ` Ray Andrews
2014-03-18 16:47               ` Peter Stephenson
2014-03-18 17:45               ` Bart Schaefer
2014-03-18 22:08                 ` Ray Andrews
2014-03-18 23:12                   ` Jan Larres
2014-03-19  4:06                     ` Ray Andrews
2014-03-19  5:30                       ` Jan Larres
2014-03-19 15:23                         ` Ray Andrews
2014-03-19 20:00                           ` Bart Schaefer
2014-03-20  1:47                             ` Ray Andrews
2014-03-19  1:17                   ` Bart Schaefer
2014-03-19  5:00                     ` Ray Andrews
2014-03-19  6:37                       ` Bart Schaefer
2014-03-19 17:08                         ` Ray Andrews [this message]
2014-03-19 17:22                           ` Roman Neuhauser
2014-03-19 22:21                           ` Bart Schaefer
2014-03-20  1:46                             ` Ray Andrews
2014-03-20  4:21                               ` Bart Schaefer
2014-03-20 15:49                                 ` Ray Andrews
2014-03-20 16:08                                   ` Bart Schaefer
2014-03-20 21:27                                     ` Ray Andrews
2014-03-19 10:00                       ` Roman Neuhauser

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=5329CF1C.5020109@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --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).