[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fwd: Strange results
From: |
Kerin Millar |
Subject: |
Re: Fwd: Strange results |
Date: |
Thu, 26 Oct 2023 20:50:00 +0100 |
On Fri, 27 Oct 2023 02:00:01 +0700
Victor Pasko <victor.pasko@gmail.com> wrote:
> ---------- Forwarded message ---------
> From: Victor Pasko <victor.pasko@gmail.com>
> Date: Fri, Oct 27, 2023 at 1:57 AM
> Subject: Re: Strange results
> To: Dennis Williamson <dennistwilliamson@gmail.com>
>
>
>
> Also
>
> echo10 ${ASCII_SET:$((-10)):1}
This is the "Substring Expansion" kind of parameter expansion.
>
> and
>
> echo11 ${ASCII_SET:-10:1}
This is the "Use Default Values" kind of parameter expansion.
>
> have different behaviour:(
Substring expansions already imply a numeric context. A single pair of
enclosing brackets is enough to avoid this pitfall.
${ASCII_SET:(-10):1}
Another method is to have a leading space.
${ASCII_SET: -10:1}
>
> Both of these say "output the character that's 10th from the end" which is
> > "u". What did you expect it to output?
> >
> > echo "echo11 ${ASCII_SET:-10:1}"
> >
>
> Firstly, expected the only one symbol from ASCII_SET string
>
> This says, according to the man page:
> >
> > ${parameter:-word}
> > Use Default Values. If parameter is unset or null, the
> > expansion of word is substituted. Otherwise, the value of parameter is
> > substituted
> >
> > which means output "10:1" if ASCII_SET is unset or null. Since it isn't,
> > the contents of that variable are output giving you a long sequence of
> > ASCII characters.
> >
>
> But ASCII_SET is not unset so -word must not be used
It behaves precisely as the manual states. The parameter, ASCII_SET, is neither
unset nor null (empty). Therefore, the value of the parameter is substituted,
rather than the given word of "10:1".
--
Kerin Millar
- Strange results, Victor Pasko, 2023/10/26
- Message not available
- Message not available
- Fwd: Strange results, Victor Pasko, 2023/10/26
- Re: Strange results, alex xmb sw ratchev, 2023/10/26
- Re: Fwd: Strange results,
Kerin Millar <=
- Re: Fwd: Strange results, Victor Pasko, 2023/10/27
- Re: Fwd: Strange results, Kerin Millar, 2023/10/27
- Re: Fwd: Strange results, Kerin Millar, 2023/10/27
- Re: Fwd: Strange results, Kerin Millar, 2023/10/27