zsh-users
 help / color / mirror / code / Atom feed
* Mysterious (debug?) output in loop
@ 2023-01-29 20:13 Dominik Vogt
  2023-01-29 20:20 ` Roman Perepelitsa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dominik Vogt @ 2023-01-29 20:13 UTC (permalink / raw)
  To: Zsh Users

Running this script

--- snip ---
#!/usr/bin/zsh
emulate zsh
repeat 3; do
	local FOO
	FOO="0"
done
--- snip ---

Produces this output:

  $ ./foo
  FOO=0
  FOO=0

  $ zsh --version
  zsh 5.8 (x86_64-debian-linux-gnu)

Why does it print 'FOO=0' to stdout (not stderr) in all passes of
the loop except the first one?  Is that some forgotten debug
output?  Is there a way to disable that (without writing the
script in a different way)?

Of course I'm aware that (a) using local variables in global scope
is useless and (b) variables are local to functions, not local to
loops.  Before stripping down the test case, it was some code in a
function.  Moving 'local FOO' out of the loop, or replacing it
with 'local FOO="0"' suppresses the output.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt


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

* Re: Mysterious (debug?) output in loop
  2023-01-29 20:13 Mysterious (debug?) output in loop Dominik Vogt
@ 2023-01-29 20:20 ` Roman Perepelitsa
  2023-01-29 20:22 ` Bart Schaefer
  2023-01-30 10:12 ` Sebastian Gniazdowski
  2 siblings, 0 replies; 4+ messages in thread
From: Roman Perepelitsa @ 2023-01-29 20:20 UTC (permalink / raw)
  To: dominik.vogt, Zsh Users

On Sun, Jan 29, 2023 at 9:19 PM Dominik Vogt <dominik.vogt@gmx.de> wrote:
>
> Running this script
>
> --- snip ---
> #!/usr/bin/zsh
> emulate zsh
> repeat 3; do
>         local FOO
>         FOO="0"
> done
> --- snip ---
>
> Produces this output:
>
>   $ ./foo
>   FOO=0
>   FOO=0
>
>   $ zsh --version
>   zsh 5.8 (x86_64-debian-linux-gnu)
>
> Why does it print 'FOO=0' to stdout (not stderr) in all passes of
> the loop except the first one?

That's what `local` does by default. You can `setopt typeset_silent`
to disable this (I always do in all my scripts).

Roman.


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

* Re: Mysterious (debug?) output in loop
  2023-01-29 20:13 Mysterious (debug?) output in loop Dominik Vogt
  2023-01-29 20:20 ` Roman Perepelitsa
@ 2023-01-29 20:22 ` Bart Schaefer
  2023-01-30 10:12 ` Sebastian Gniazdowski
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2023-01-29 20:22 UTC (permalink / raw)
  To: dominik.vogt, Zsh Users

On Sun, Jan 29, 2023 at 12:18 PM Dominik Vogt <dominik.vogt@gmx.de> wrote:
>
> Why does it print 'FOO=0' to stdout (not stderr) in all passes of
> the loop except the first one?

Doc reference:

     If the shell option TYPESET_SILENT is not set, for each remaining
     NAME that refers to a parameter that is already set, the name and
     value of the parameter are printed in the form of an assignment.
     Nothing is printed for newly-created parameters, or when any
     attribute flags listed below are given along with the NAME.


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

* Re: Mysterious (debug?) output in loop
  2023-01-29 20:13 Mysterious (debug?) output in loop Dominik Vogt
  2023-01-29 20:20 ` Roman Perepelitsa
  2023-01-29 20:22 ` Bart Schaefer
@ 2023-01-30 10:12 ` Sebastian Gniazdowski
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-30 10:12 UTC (permalink / raw)
  To: dominik.vogt, Zsh Users

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

You can find some other useful options here:
https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html#std-options

niedz., 29 sty 2023, 21:19 użytkownik Dominik Vogt <dominik.vogt@gmx.de>
napisał:

> Running this script
>
> --- snip ---
> #!/usr/bin/zsh
> emulate zsh
> repeat 3; do
>         local FOO
>         FOO="0"
> done
> --- snip ---
>
> Produces this output:
>
>   $ ./foo
>   FOO=0
>   FOO=0
>
>   $ zsh --version
>   zsh 5.8 (x86_64-debian-linux-gnu)
>
> Why does it print 'FOO=0' to stdout (not stderr) in all passes of
> the loop except the first one?  Is that some forgotten debug
> output?  Is there a way to disable that (without writing the
> script in a different way)?
>
> Of course I'm aware that (a) using local variables in global scope
> is useless and (b) variables are local to functions, not local to
> loops.  Before stripping down the test case, it was some code in a
> function.  Moving 'local FOO' out of the loop, or replacing it
> with 'local FOO="0"' suppresses the output.
>
> Ciao
>
> Dominik ^_^  ^_^
>
> --
>
> Dominik Vogt
>
>

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

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

end of thread, other threads:[~2023-01-30 10:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-29 20:13 Mysterious (debug?) output in loop Dominik Vogt
2023-01-29 20:20 ` Roman Perepelitsa
2023-01-29 20:22 ` Bart Schaefer
2023-01-30 10:12 ` Sebastian Gniazdowski

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