[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ${param+x} ?
From: |
alex xmb sw ratchev |
Subject: |
Re: ${param+x} ? |
Date: |
Tue, 19 Dec 2023 12:39:54 +0100 |
${parameter:-word}
Use Default Values. If parameter is unset or null,
the expansion of word is substituted. Otherwise, the
value of parameter is substituted.
${parameter:=word} Assign
Default Values. If parameter is unset or null,
the expansion of word is assigned to parameter. The
value of parameter is then substituted. Positional
parameters and special parameters may not be assigned
to in this way.
${parameter:?word}
Display Error if Null or Unset. If parameter is null
or unset, the expansion of word (or a message to that
effect if word is not present) is written to the
standard error and the shell, if it is not
interactive, exits. Otherwise, the value of parameter
is substituted.
${parameter:+word}
Use Alternate Value. If parameter is null or unset,
nothing is substituted, otherwise the expansion of
word is substituted.
${parameter:offset}
${parameter:offset:length}
Substring Expansion. Expands to up to length
characters of the value of parameter starting at the
character specified by offset. If parameter is @ or
*, an indexed array subscripted by @ or *, or an
associative array name, the results differ as
described below. If length is omitted, expands to the
substring of the value of parameter starting at the
character specified by offset and extending to the end
of the value. length and offset are arithmetic
expressions (see ARITHMETIC EVALUATION below).
On Tue, Dec 19, 2023, 11:47 AM lacsaP Patatetom <patatetom@gmail.com> wrote:
> Le mar. 19 déc. 2023 à 11:38, lacsaP Patatetom <patatetom@gmail.com> a
> écrit :
>
> > hi,
> >
> > this form `${param+x}` is not documented (man) but is accepted by bash
> and
> > differs from `${param:+x}` :
> > `unset p; echo -n ${param+x} && echo -n ${param:+y}` return nothing,
> > `p=''; echo -n ${param+x} && echo -n ${param:+y}` return `x` and
> > `p='test'; echo -n ${param+x} && echo -n ${param:+y}` return `xy`
> >
> > is it possible to get an explanation ?
> >
> > it is found in a script in this test :
> > [ -z ${param+x} ]
> >
> > what's the point of this test, which will always be true ?
> >
> > regards, lacsaP.
> >
>
> last-minute formatting is never good ;-)
> `p` is `param`
> `unset param; echo -n ${param+x} && echo -n ${param:+y}` return nothing,
> `param=''; echo -n ${param+x} && echo -n ${param:+y}` return `x` and
> `param='test'; echo -n ${param+x} && echo -n ${param:+y}` return `xy`
> sorry
>