[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why fail , [[ $sep$*$sep == $sep--$sep ]]
From: |
Kerin Millar |
Subject: |
Re: why fail , [[ $sep$*$sep == $sep--$sep ]] |
Date: |
Sun, 18 Feb 2024 21:37:08 +0000 |
On Sun, 18 Feb 2024 15:56:45 -0500
Lawrence Velázquez <vq@larryv.me> wrote:
> On Sun, Feb 18, 2024, at 8:51 AM, Kerin Millar wrote:
> > On Sun, 18 Feb 2024 14:34:43 +0100
> > alex xmb sw ratchev <fxmbsw7@gmail.com> wrote:
> >
> >> On Sun, Feb 18, 2024, 14:18 Kerin Millar <kfm@plushkava.net> wrote:
> >>
> >> > On Sat, 17 Feb 2024 17:01:13 +0100
> >> > alex xmb sw ratchev <fxmbsw7@gmail.com> wrote:
> >> >
> >> > > oh i know why it failed
> >> > > set interprets the first -- away
> >> >
> >> > That is not why it is failing to behave as you expect. Rather, the issue
> >> > is that your conditional expression is incorrect. It should be [[
> >> > "$f$*$f"
> >> > == *"$f--$f"* ]]. Note that you have chosen to change the value of IFS.
> >> > It
> >> > is important that you do not omit the quotes - not even for the left hand
> >> > side of the expression!
> >> >
> >>
> >> i thought there is a ' flat left side of == '
> >
> > Unfortunately, the raw output of xtrace is not much use for human
> > eyeballs. Here's the exact difference.
> >
> > $ ( set aa bb cc -- dd; f=$'\1' IFS=$f PS4= BASH_XTRACEFD=1; set -x; [[
> > "$f$*$f" == *"$f--$f"* ]] ) | hexdump -C
> > 00000000 5b 5b 20 01 61 61 01 62 62 01 63 63 01 2d 2d 01 |[[
> > .aa.bb.cc.--.|
> > 00000010 64 64 01 20 3d 3d 20 2a 01 5c 2d 5c 2d 01 2a 20 |dd. ==
> > *.\-\-.* |
> > 00000020 5d 5d 0a |]].|
> >
> > $ ( set aa bb cc -- dd; f=$'\1' IFS=$f PS4= BASH_XTRACEFD=1; set -x; [[
> > $f$*$f == *"$f--$f"* ]] ) | hexdump -C
> > 00000000 5b 5b 20 61 61 62 62 63 63 2d 2d 64 64 20 3d 3d |[[
> > aabbcc--dd ==|
> > 00000010 20 2a 01 5c 2d 5c 2d 01 2a 20 5d 5d 0a | *.\-\-.*
> > ]].|
>
> This surprises me because IFS is not lost if it's set to something
> a little less ... weird:
>
> $ (set aa bb cc -- dd; f=+ IFS=$f; set -x; [[ $f$*$f == *"$f--$f"* ]])
> + [[ +aa+bb+cc+--+dd+ == *\+\-\-\+* ]]
>
> Why the difference?
Why indeed. This must surely be a bug. Neither of + and $'\1' are the standard
whitespace characters (in view of field splitting). There is no reason for them
to be handled inconsistently.
--
Kerin Millar
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], (continued)
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], alex xmb sw ratchev, 2024/02/17
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], alex xmb sw ratchev, 2024/02/17
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Kerin Millar, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], alex xmb sw ratchev, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Kerin Millar, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], alex xmb sw ratchev, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], alex xmb sw ratchev, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Kerin Millar, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Chet Ramey, 2024/02/20
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Lawrence Velázquez, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]],
Kerin Millar <=
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Greg Wooledge, 2024/02/18
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Chet Ramey, 2024/02/20
- Re: why fail , [[ $sep$*$sep == $sep--$sep ]], alex xmb sw ratchev, 2024/02/20
Re: why fail , [[ $sep$*$sep == $sep--$sep ]], Chet Ramey, 2024/02/20