zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: var=$( typeset "$1" ) ... not within a function.
Date: Thu, 20 Oct 2022 17:54:21 -0700	[thread overview]
Message-ID: <CAH+w=7auK9J5y=Eag1k5rOz=zys6n4GnfM_+mYpYLmXWoMdNPQ@mail.gmail.com> (raw)
In-Reply-To: <552657de-31ce-255a-bc8d-7c9cd4b8eabd@eastlink.ca>

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

On Thu, Oct 20, 2022 at 1:48 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> typeset scares
> me because sometimes it's a passive reporter, other times dangerously
> active

Yes, it's unfortunate that typeset (without options) was ever given
the function you describe as "passive reporter".  Worse that it's
synonym "declare" behaves the same.

> in this case I was just looking for information

There are two typeset options specifically for that purpose: -p, which
prints "typeset" commands so you can replay them e.g. with "eval" or
from a script file, and "+" (all by itself), which either prints all
the parameter names (and only the names), or the assignment form of
whatever names follow it.  (The manual still doesn't explain the
latter effect, I see, claiming that nothing is allowed to follow a
bare "+" sign.)

> but it seems
> like I created a parameter -- which '-m' seems to prevent.

The -m option actually is for pattern-matching and is intended to be
combined with other options ... when you use it without any others, it
has the effect of canceling "what typeset does when there are no
options", and that accidentally produces the effect you wanted.

[-- Attachment #2: doc-typeset-plus.txt --]
[-- Type: text/plain, Size: 1467 bytes --]

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 641e46cf9..dd54a0fc8 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -2047,8 +2047,9 @@ startitem()
 item(tt(PLUS()))(
 If `tt(PLUS())' appears by itself in a separate word as the last option,
 then the names of all parameters (functions with tt(-f)) are printed, but
-the values (function bodies) are not.  No var(name) arguments may appear,
-and it is an error for any other options to follow `tt(PLUS())'.  The
+the values (function bodies) are not.  If var(name) arguments appear,
+both those names and their values are printed in the form of assignments.
+It is an error for any other options to follow `tt(PLUS())', but the
 effect of `tt(PLUS())' is as if all attribute flags which precede it were
 given with a `tt(PLUS())' prefix.  For example, `tt(typeset -U PLUS())' is
 equivalent to `tt(typeset +U)' and displays the names of all arrays having
@@ -2081,7 +2082,8 @@ Except when assignments are made with var(name)tt(=)var(value), using
 tt(+m) forces the matching parameters and their attributes to be printed,
 even inside a function.  Note that tt(-m) is ignored if no patterns are
 given, so `tt(typeset -m)' displays attributes but `tt(typeset -a +m)'
-does not.
+does not.  Ordinary scalar string parameters have no attributes, so for
+those tt(+m) prints only the names.
 )
 item(tt(-p) [ var(n) ])(
 If the tt(-p) option is given, parameters and values are printed in the

  reply	other threads:[~2022-10-21  0:55 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20 17:21 Ray Andrews
2022-10-20 17:25 ` Roman Perepelitsa
2022-10-20 17:51   ` Ray Andrews
2022-10-20 17:54     ` Roman Perepelitsa
2022-10-20 18:38       ` Ray Andrews
2022-10-20 18:44         ` Roman Perepelitsa
2022-10-20 19:15           ` Ray Andrews
2022-10-20 19:35             ` Roman Perepelitsa
2022-10-20 20:48               ` Ray Andrews
2022-10-21  0:54                 ` Bart Schaefer [this message]
2022-10-21  1:58                   ` Ray Andrews
2022-10-21  2:25                     ` Bart Schaefer
2022-10-21 14:24                       ` Ray Andrews
2022-10-21 14:37                         ` Ray Andrews
2022-10-21 17:34                         ` Roman Perepelitsa
2022-11-01  5:00                       ` "typeset -p" inconsistency Bart Schaefer
2022-11-01 12:07                         ` Peter Stephenson
2022-11-01 12:40                         ` Ray Andrews
2022-11-01 19:08                           ` Bart Schaefer
2022-11-01 21:25                             ` Ray Andrews
2022-11-01 21:40                               ` Bart Schaefer
2022-11-01 22:46                                 ` Ray Andrews
2022-11-02  1:13                                   ` Lawrence Velázquez
2022-11-02  2:42                                     ` Ray Andrews
2022-11-02  3:11                                       ` Lawrence Velázquez
2022-11-02 12:56                                         ` Ray Andrews
2022-11-02 17:04                                           ` Bart Schaefer
2022-11-02 17:19                                             ` Ray Andrews
2022-11-02 18:21                                               ` Bart Schaefer
2022-11-02  3:10                                   ` Bart Schaefer
2022-11-02 17:09                                     ` Ray Andrews
2022-10-20 17:29 ` var=$( typeset "$1" ) ... not within a function Mikael Magnusson
2022-10-20 17:43   ` Ray Andrews
2022-10-21 17:33 ` Ray Andrews
2022-10-21 18:25   ` Bart Schaefer
2022-10-21 18:57     ` Ray Andrews
2022-10-21 19:02       ` Roman Perepelitsa
2022-10-21 19:06         ` Ray Andrews
2022-10-21 19:04     ` Ray Andrews

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='CAH+w=7auK9J5y=Eag1k5rOz=zys6n4GnfM_+mYpYLmXWoMdNPQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=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).