Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Modifiers and parameter expansion?
- X-seq: zsh-users 28474
- From: Dominik Vogt <dominik.vogt@xxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Modifiers and parameter expansion?
- Date: Fri, 2 Dec 2022 03:47:46 +0100
- Archived-at: <https://zsh.org/users/28474>
- In-reply-to: <CAH+w=7ZFbSnx74mr=ZjRzfUQP0k6i9Xime3E1sCytaios-HqDA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- References: <Y4kcyW/acG5cPz+o@localhost> <1dcdd69c-ce29-921f-f0f0-6862f68b62a6@gmx.com> <CAH+w=7amodhidc8i1MqPWkqhYv2PkN56WmZQ8e-g-GU6p3F6GA@mail.gmail.com> <Y4ktCdAPhIVR7bGk@localhost> <CAH+w=7b5rQNkfQcRb1zVDbD5CMn-8F67pGS9JvshqyRiFF6nXw@mail.gmail.com> <Y4lMMptVvkj62FF3@localhost> <CAH+w=7ZFbSnx74mr=ZjRzfUQP0k6i9Xime3E1sCytaios-HqDA@mail.gmail.com>
- Reply-to: dominik.vogt@xxxxxx
- Ui-outboundreport: notjunk:1;M01:P0:oGPm9QCndy4=;EXS1fvqiQdFqyFU36INNc+wlpKy xyBrSRaYMTmz1oTgW3gNK1X4QNeSxPDbz+jzC2nj73/Nr3WD509YoMvQOkuDzXWwupGhUtgBG tXzkDTjmf3kopIsrcIqFfBnZFYIAIS+GySSVM/iD1/MJvByizkmHT1kwIfFg8i+H1u4Y8iv/J VFZpXPm1qyT/AcusnjX1kCixheBRVodWvA8MiUJIVI4mDdufapEeBck3eiRRXukNFIeCaRq8j hGIRqvWgYZtpOKmLjXN3cYTOW4YeeLdn1h6Y3oUaZp5LTNU512mEmThFmk2P2fsBG9bFJS3Ow CUwhOMa9acqbBXuMvyP26SJsLvDT7UDL3aMhtnGfbMqjBhN1RKhZMDIf8kZGfeEPNDU3xDWns bSEbhupsB+WF9q8pvjsOp26T0VS2ZDNELY7N+m21MjhWKgQs+ZIXQYLegOpWos9TfSsOcMgDg AQoYHgl0RHbdkkxDcTgFao0WsHmlmTiODFj5IdENC92+0GyqH2c5ZcqHYY5GAkeyOaP0MSKSt U2qBdTlZ2Gw7aO/TbionwWHEqN5DJtj6wLfXbaduZPRgHP56S+MXr3770Ywm0MLc41mPzl1pq aXKcCXSM+EYGjgDiW66T9KeFbwACz4MulpeEamrBbwMF3Yg/uuNqkK1CGJ5MzCDHSFi2Dhai1 ouBWAzHHkcDhjyivexKBsJR7Q8OcCGzV9DPAXv/WHXrH6nAqhFmP/HG0l6YssCyeetIhSC8zx wAcQuxhdzGqHXEXVt3K7qsdv77mWC+CpxTDRrdWUTBVTIVAlHATQZwKN1vH2ebKQr1rSu9Wy/ POoEWAPrH3q38VHNAudQuo473jTmv0zH1/qjXiGa6w+ymXSUEqaTSjfPzwOpD2stcz7JPw2E6 7CEHyl7zaydym6K5NWxNHtTHTTNbN2jMytYLQBmAnfe/EFgr5St+mJdvYkEA071SvjgoMLtmY 4TbVh/f19cT8oMgvZ7lgUZb7xUc=
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