From: Dominik Vogt <dominik.vogt@gmx.de>
To: zsh-users@zsh.org
Subject: Re: Modifiers and parameter expansion?
Date: Fri, 2 Dec 2022 03:47:46 +0100 [thread overview]
Message-ID: <Y4lnUsJbhruCjU1V@localhost> (raw)
In-Reply-To: <CAH+w=7ZFbSnx74mr=ZjRzfUQP0k6i9Xime3E1sCytaios-HqDA@mail.gmail.com>
On Thu, Dec 01, 2022 at 05:34:18PM -0800, Bart Schaefer wrote:
> On Thu, Dec 1, 2022 at 4:52 PM Dominik Vogt <dominik.vogt@gmx.de> wrote:
> >
> > > > 7. Modifiers
> >
> > Okay. Why are "%" "%%" "#" "##" "/" "//" refered to in this
> > section?
>
> Because they happen to be interpreted at the same "step" as modifiers,
> and the documentation grew organically?
>
> > > In the Parameter Expansion section
> > >
> > > ${NAME}
> >
> > The braces are required unless(1) they are not(2) required
> > unless(3) some option is not(4) present. Quadruple negative.
>
> Not sure where you came up with that.
[Implicit: the braces can be omitted, unless] -> negation 1
... more complicated forms ... require ... exceptions -> negation 2
... which only apply if -> negation 3
... option is not set -> negation 4
(The implicit statement is the _only_ "mention" of the brace-less
form at all.)
--
> > $ echo ~a
>
> No, that's completely irrelevant. The BRACES aren't required, but the
> $ IS. The above is not parameter expansion.
Right, sorry.
--
> KSH_ARRAYS requires
> ${X[2]}
> ${X:h}
> ${^X}
True.
> ${=X}
> ${~X}
> ${#X}
> ${+X}
These work without braces even if KSH_ARRAYS is set.
$ emulate zsh; setopt KSH_ARRAYS
### $=X
$ X='abc def'
$ A=("$X"); echo ${#A[@]}
1
$ B=("$=X"); echo ${#B[@]}
2
$ unsetopt KSH_ARRAYS
$ C=("$=X"); echo ${#C[@]}
2
$ setopt KSH_ARRAYS
### $~X
$ mkdir tmp; cd tmp; touch a b
$ A='*'; echo $~A; echo $A
a b
*
### $+X
$ A="val"; unset B; echo $+A $+B
1 0
Still works (but ksh-array-ish for arrays):
### $#X
$ A=(aa bb cc); B="abc"; echo $#A $#B
2 3
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
next prev parent reply other threads:[~2022-12-02 2:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 21:29 Dominik Vogt
2022-12-01 21:34 ` Eric Cook
2022-12-01 21:36 ` Bart Schaefer
2022-12-01 22:39 ` Dominik Vogt
2022-12-01 23:42 ` Bart Schaefer
2022-12-02 0:52 ` Dominik Vogt
2022-12-02 1:34 ` Bart Schaefer
2022-12-02 2:47 ` Dominik Vogt [this message]
2022-12-02 17:59 ` Bart Schaefer
2022-12-02 1:28 ` Dominik Vogt
2022-12-02 1:48 ` 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=Y4lnUsJbhruCjU1V@localhost \
--to=dominik.vogt@gmx.de \
--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).