[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fwd: Strange results
From: |
Victor Pasko |
Subject: |
Re: Fwd: Strange results |
Date: |
Fri, 27 Oct 2023 19:28:15 +0700 |
See my comments below inline
On Fri, Oct 27, 2023 at 2:50 AM Kerin Millar <kfm@plushkava.net> wrote:
> 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}
>
Well, it's kind of a workaround to use brackets or extra space, but how to
recognize such expectations according to string operation with -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".
>
How to recognize such expectations according to string operation with
-10:1 ?
--
> Kerin Millar
>
Let me ask more questions presented in the sent bug2.bash
Look at the following lines:
*printf -v a_int '%d' "'a" *# very strange syntax here to use char as
integer
echo "echo4 $a_int" # should be 97 at the end
echo "echo5 *${ASCII_SET:$((a_int-12)):1}" *# you can see letter u at the
end as at 97-12=85 place
echo "echo5.1 ${ASCII_SET:a_int-12:1}" # you can see letter u at the end
as at 97-12=85 place
1) Could you please suggest elegant way to cast string symbol to
integer instead of printf for * "'a"*
2) Here are some unsuccessful examples to use bitwise operations with
symbols:
% echo $(("'a" >> 4))
-bash: 'a >> 4: syntax error: operand expected (error token is "'a >> 4")
% echo $(("a" >> 4))
0
% echo -n $(("a" >> 4)) | xxd -p
30
% echo -n $(("a" >> 2)) | xxd -p
30
--
-- PSK
- 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, 2023/10/26
- Re: Fwd: Strange results,
Victor Pasko <=
- 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