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: Tue, 18 Mar 2014 09:22:22 -0700	[thread overview]
Message-ID: <532872BE.1020408@eastlink.ca> (raw)
In-Reply-To: <140317235020.ZM30413@torch.brasslantern.com>

On 03/17/2014 11:50 PM, Bart Schaefer wrote:


Bart:

Confusions within Confuzzlements.
> I'm not able to reproduce this:
>
> zsh -f
> torch% func() { set -F; read -t input; print "$input to a summer's day?" }
> torch% echo "Shall I compare thee" | func
> Shall I compare thee to a summer's day?
> torch%
Yeah, that works, but your further comments expose what seems to me to 
be a bug.
> Further, "read -t" means to fail immediately if input is not ready
> when "read" begins executing.  Because zsh forks to the left, there
> is an inherent race condition in having "read -t" on the right side
> of a pipeline; the "echo" in the forked subshell may not yet have
> had a chance to do anything by the time that the "read" in the parent
> shell examines standard input.
>
> Try examining $? after "read -t input" finishes.  If it's 1, then the
> read timed out.
>
> If you change to "read -t 1 input" you may find the problem disappears.

Your code:

   func0() { set -F; read -t input; print "$input to a summer's day?" }

And this run:

   $ s="lowercase s"; S=UPPERCASE S"

   $ echo "$s $S"
   lowercase s UPPERCASE S

   $ echo $S | func0
   UPPERCASE S to a summer's day?

   $ echo $s | func0
   lowercase s to a summer's day?

   $ echo $S | func0
   lowercase s to a summer's day?   << WRONG!

   $ echo "$s $S"
   lowercase s UPPERCASE S

   $ echo $S | func0
   UPPERCASE S to a summer's day?  << THAT'S BETTER

... How can such a thing ever be permitted? That's just plain broken.
But, from your comments I tried this: (it seems the 'set -F' thing is a 
red herring)

   func1() { read -t 1 input; print "$input to a summer's day?" }

... And the same run of tests is fine.  I have no idea how this 'race 
condition' stuff
works but surely, whatever "read -t 1" has that "read -t" lacks should 
be automatic?
When/where would my first run above ever be acceptable? It should print 
the correct
variable, or maybe it should fail completely, but printing the wrong 
variable is just a felony, no?
Nothing is more important than predictability. In a pipe situation, 
'read' shouldn't leave
the station until all the passengers are on board, but even if it does, 
it shouldn't give my
seat to someone else and then call them me.  Or so it looks to this 
grasshopper.


  reply	other threads:[~2014-03-18 16:22 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 [this message]
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
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=532872BE.1020408@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).