zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: zsh-users@zsh.org
Subject: Re: manual
Date: Thu, 22 Dec 2022 02:03:16 -0500	[thread overview]
Message-ID: <a6b802da-7787-4de0-8713-679679d70971@app.fastmail.com> (raw)
In-Reply-To: <71c9c7e9-3f95-143d-fbd6-6575d7f4c446@eastlink.ca>

On Tue, Dec 20, 2022, at 5:41 PM, Ray Andrews wrote:
> Daniel was interested in what I'd do with the 'set' man page.  It has a 
> completely different flavor but:
>
> 'set' has too many uses:
>
> 1): set [+]
> 2): set {+|-}s [STRING] [STRING] ...
> 3): set {+|-}s -A [ARRAY_NAME] [VALUE]
> 4): set        +A [ARRAY_NAME] [VALUE]         # sorting not available 
> with '+A'
> 5): set {+|-}OPTION_NAME
> 6): set +o
> 7): set -o
> 8): set {+|-}o [OPTION_NAME] [OPTION_NAME]  ... [--]

Partitioning the synopsis isn't a bad idea, but your partition is
misleading because most of the options you separated can actually
be used together in a single "set" command.

	% print $options[ALIASES] $options[ERR_EXIT]
	on off
	% typeset -p argv
	typeset -a argv=(  )
	% set +o ALIASES -e foo bar baz
	% print $options[ALIASES] $options[ERR_EXIT]
	off on
	% typeset -p argv
	typeset -a argv=( foo bar baz )
	% typeset -p arr || true
	typeset: no such variable: arr
	% set -o ALIASES +e -A arr v1 v2 v3
	% print $options[ALIASES] $options[ERR_EXIT]
	on off
	% typeset -p arr
	typeset -a arr=( v1 v2 v3 )

POSIX.1-2017 does partition its synopsis [*], but later it has to
explicitly explain that setting and unsetting attributes can be
mixed in a single invocation because the synopsis implies otherwise.

	set [-abCefhmnuvx] [-o option] [argument...]
	set [+abCefhmnuvx] [+o option] [argument...]
	set -- [argument...]
	set -o
	set +o

[*]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set


> 2): set {+|-}s [STRING] [STRING] ... :

The term "string" is next to useless when discussing shell.  Almost
everything is what you might consider a string.


> If no flags other than +s or -s are given then the arguments following 
> 'set' are assigned to the
> positional parameters:

As I already mentioned, this is incorrect.  Options and positional
parameters can be mixed in the same invocation.


> 3): set {+|-}s -A [ARRAY_NAME] [VALUE]:
> ARRAY_NAME is set to VALUE, completely erasing any former contents:
>
> 4): set +A [ARRAY_NAME] [VALUE]:
> ARRAY_NAME is overwritten by the new VALUE but not truncated if the new
> VALUE is shorter than the old.

These are incorrect.  Multiple arguments can be provided, all of
which are assigned to the array.  Additionally, -s and +s work with
+A, and it is not clear what "value" is supposed to mean.


> Note that 'typeset -A' is quite different from 'set -A'!  If you are 
> copying an
> associative array to another array you must do this:
>
> $ typeset -A NEW_ARRAY
> $ set -A NEW_ARRAY OLD_ARRAY

This example incorrectly implies that this should work:

	% typeset -A old_arr=(a 1 b 2 c 3)
	% typeset -A new_arr
	% set -A new_arr old_arr
	zsh: bad set of key/value pairs for associative array


> 5): set {+|-}[OPTION]
> Turn on|off a single OPTION.

This incorrectly implies that it is not possible to enable options,
disable options, and set positional parameters in the same invocation.


> 8): set {+|-}o [OPTION] [OPTION} ... [--]
> Turn on|off the given OPTIONS.  If the list is followed by '--' the 
> positional
> parameters will be unset.

It is not possible to enable or disable multiple options this way.
All but the first will actually be used as positional parameters.

	% set -o EXTENDED_GLOB ERR_EXIT
	% print $options[EXTENDED_GLOB] $options[ERR_EXIT]
	on off
	% typeset -p argv
	typeset -a argv=( ERR_EXIT )

Additionally, this incorrectly implies that the positional parameters
can only be cleared after -o or +o.


>                For historical reasons, `set -' is treated as `set +xv' 
> and `set - args' as
>                `set +xv -- args' when in any other emulation mode than 
> zsh's native mode.
>
> DON'T KNOW WHAT TO DO WITH THAT.

Leave it in?


-- 
vq


  parent reply	other threads:[~2022-12-22  7:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-20 22:41 manual Ray Andrews
2022-12-21  0:43 ` manual Lawrence Velázquez
2022-12-21  1:15   ` manual Ray Andrews
2022-12-21  1:44     ` manual Lawrence Velázquez
2022-12-21  4:15       ` manual Ray Andrews
2022-12-21  2:00 ` manual Daniel Shahaf
2022-12-21  4:12   ` manual Ray Andrews
2022-12-21  4:43   ` manual Bart Schaefer
2022-12-21 14:04     ` manual Ray Andrews
2022-12-22  6:31       ` manual Lawrence Velázquez
2022-12-22 14:20         ` manual Ray Andrews
2022-12-21  9:38   ` manual Lawrence Velázquez
2022-12-22  7:03 ` Lawrence Velázquez [this message]
2022-12-22 13:50   ` manual 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=a6b802da-7787-4de0-8713-679679d70971@app.fastmail.com \
    --to=larryv@zsh.org \
    --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).