Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Modifiers and parameter expansion?



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@xxxxxx> 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




Messages sorted by: Reverse Date, Date, Thread, Author