zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: minor 'select' snag
Date: Mon, 15 Feb 2016 12:48:03 +0000	[thread overview]
Message-ID: <20160215124803.6d07e989@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <56C10822.9010107@inlv.org>

On Mon, 15 Feb 2016 00:05:06 +0100
Martijn Dekker <martijn@inlv.org> wrote:
> I'm analysing the behaviour of 'select' in various shells and found a a
> way in which it's different in zsh from bash, ksh93 and {pd,m}ksh.
> 
> If a user presses Ctrl-D (EOF) within a 'select' loop, the REPLY
> variable is left unchanged on zsh. On the other shells with 'select', it
> is cleared, which is the same behaviour as 'read' (including 'read' on
> zsh) and seems more logical. This makes it possible to decide whether to
> continue after the loop by testing for the emptiness of $REPLY without
> having to initialise it before entering the loop. It would be nice if
> this worked the same way on zsh.

This looks easy.  I don't think there's any existing moral right to
expect REPLY to be unaffected in such circumstances.

diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo
index 2a76964..7488829 100644
--- a/Doc/Zsh/grammar.yo
+++ b/Doc/Zsh/grammar.yo
@@ -279,8 +279,10 @@ is set to the var(word) corresponding to this number.
 If this line is empty, the selection list is printed again.
 Otherwise, the value of the parameter var(name) is set to null.
 The contents of the line read from standard input is saved
-in the parameter tt(REPLY).  var(list) is executed
-for each selection until a break or end-of-file is encountered.
+in the parameter tt(REPLY); this is set to the empty string if no
+input was done for the benefit of code following the tt(select).
+var(list) is executed for each selection until a break or end-of-file is
+encountered.
 )
 cindex(subshell)
 item(tt(LPAR()) var(list) tt(RPAR()))(
diff --git a/Src/loop.c b/Src/loop.c
index 19d7f73..dd4b282 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -224,6 +224,7 @@ execselect(Estate state, UNUSED(int do_exec))
     size_t more;
     LinkList args;
     int old_simple_pline = simple_pline;
+    int reply_set = 0;
 
     /* See comments in execwhile() */
     simple_pline = 1;
@@ -303,6 +304,7 @@ execselect(Estate state, UNUSED(int do_exec))
 	    more = selectlist(args, more);
 	}
 	setsparam("REPLY", ztrdup(str));
+	reply_set = 1;
 	i = atoi(str);
 	if (!i)
 	    str = "";
@@ -327,6 +329,8 @@ execselect(Estate state, UNUSED(int do_exec))
 	    break;
     }
   done:
+    if (!reply_set)
+	setsparam("REPLY", ztrdup(""));
     cmdpop();
     popheap();
     fclose(inp);


  reply	other threads:[~2016-02-15 12:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-14 23:05 Martijn Dekker
2016-02-15 12:48 ` Peter Stephenson [this message]
2016-02-15 17:01   ` Bart Schaefer
2016-09-26 16:59   ` Martijn Dekker
2016-02-15 16:46 ` Bart Schaefer

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=20160215124803.6d07e989@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@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).