zsh-users
 help / color / mirror / code / Atom feed
* Unterminated for loop
@ 2023-06-06 18:46 Roman Perepelitsa
  2023-06-06 23:12 ` Mikael Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: Roman Perepelitsa @ 2023-06-06 18:46 UTC (permalink / raw)
  To: Zsh Users

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

If I type `for x;` (without the quotes) and press ENTER in an interactive
zsh, I end up in PS2. However, the exact same sequence of characters is
treated as a complete command in a script or function. Why is that?

    $ zsh -f
    % () { for x; }
    % zsh -fc 'for x;'
    % for x;
    for>

Roman.

[-- Attachment #2: Type: text/html, Size: 433 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unterminated for loop
  2023-06-06 18:46 Unterminated for loop Roman Perepelitsa
@ 2023-06-06 23:12 ` Mikael Magnusson
  2023-06-07  2:58   ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2023-06-06 23:12 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh Users

On 6/6/23, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> If I type `for x;` (without the quotes) and press ENTER in an interactive
> zsh, I end up in PS2. However, the exact same sequence of characters is
> treated as a complete command in a script or function. Why is that?

It is accepted because SHORT_LOOPS is unfortunately set by default,
which tends to hide a lot of syntax errors in various contexts. It's
no surprise that it causes weird differences with script EOF vs
accepting a single line interactively.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unterminated for loop
  2023-06-06 23:12 ` Mikael Magnusson
@ 2023-06-07  2:58   ` Bart Schaefer
  2023-06-07  5:43     ` Jun T
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bart Schaefer @ 2023-06-07  2:58 UTC (permalink / raw)
  To: Zsh Users

On Tue, Jun 6, 2023 at 4:12 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> On 6/6/23, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> > If I type `for x;` (without the quotes) and press ENTER in an interactive
> > zsh, I end up in PS2. However, the exact same sequence of characters is
> > treated as a complete command in a script or function. Why is that?
>
> It is accepted because SHORT_LOOPS is unfortunately set by default,
> which tends to hide a lot of syntax errors in various contexts. It's
> no surprise that it causes weird differences with script EOF vs
> accepting a single line interactively.

Tangentially, this points out that there is no way to send an EOF at
the PS2 prompt (or, likely, at any prompt other than PS1); typing
ctrl+d just lists file completions.  Even changing stty eof doesn't
work.  Nor does a custom widget that closes FD 0.

Someone please remind me what this sentence under IGNORE_EOF means?
     Also, if this option is set and the Zsh Line Editor is used,
     widgets implemented by shell functions can be bound to EOF
     (normally Control-D) without printing the normal warning message.

I guess "bound to EOF" means overriding the stty EOF character.
What's the significance of the part about the warning message?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unterminated for loop
  2023-06-07  2:58   ` Bart Schaefer
@ 2023-06-07  5:43     ` Jun T
  2023-06-07  8:13     ` Roman Perepelitsa
  2023-06-07 15:20     ` Ray Andrews
  2 siblings, 0 replies; 6+ messages in thread
From: Jun T @ 2023-06-07  5:43 UTC (permalink / raw)
  To: zsh-users


> 2023/06/07 11:58, Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
> Someone please remind me what this sentence under IGNORE_EOF means?
>     Also, if this option is set and the Zsh Line Editor is used,
>     widgets implemented by shell functions can be bound to EOF
>     (normally Control-D) without printing the normal warning message.
> 
> I guess "bound to EOF" means overriding the stty EOF character.
> What's the significance of the part about the warning message?

without getting the message "zsh: use 'exit' to exit.", I think.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unterminated for loop
  2023-06-07  2:58   ` Bart Schaefer
  2023-06-07  5:43     ` Jun T
@ 2023-06-07  8:13     ` Roman Perepelitsa
  2023-06-07 15:20     ` Ray Andrews
  2 siblings, 0 replies; 6+ messages in thread
From: Roman Perepelitsa @ 2023-06-07  8:13 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On Wed, Jun 7, 2023 at 4:59 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Someone please remind me what this sentence under IGNORE_EOF means?
>      Also, if this option is set and the Zsh Line Editor is used,
>      widgets implemented by shell functions can be bound to EOF
>      (normally Control-D) without printing the normal warning message.
>
> I guess "bound to EOF" means overriding the stty EOF character.
> What's the significance of the part about the warning message?

It means you can do this:

  setopt ignore_eof
  bindkey '^D' my-eof

I do this in my zsh config.

Roman.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unterminated for loop
  2023-06-07  2:58   ` Bart Schaefer
  2023-06-07  5:43     ` Jun T
  2023-06-07  8:13     ` Roman Perepelitsa
@ 2023-06-07 15:20     ` Ray Andrews
  2 siblings, 0 replies; 6+ messages in thread
From: Ray Andrews @ 2023-06-07 15:20 UTC (permalink / raw)
  To: zsh-users


On 2023-06-06 19:58, Bart Schaefer wrote:
>
> Someone please remind me what this sentence under IGNORE_EOF means?

I just love it when even Bart is confused by the documentation, it gives 
we ordinary mortals some comfort.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-07 15:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06 18:46 Unterminated for loop Roman Perepelitsa
2023-06-06 23:12 ` Mikael Magnusson
2023-06-07  2:58   ` Bart Schaefer
2023-06-07  5:43     ` Jun T
2023-06-07  8:13     ` Roman Perepelitsa
2023-06-07 15:20     ` Ray Andrews

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).