[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sed with Variable Substitution in the command
From: |
Andreas Kähäri |
Subject: |
Re: sed with Variable Substitution in the command |
Date: |
Fri, 27 Sep 2024 13:50:25 +0200 |
On Fri, Sep 27, 2024 at 01:35:04PM +0200, alex xmb sw ratchev wrote:
> huuuu , yeah fail test
>
> {13..1}
> bash returns wrong 1 at end for $11
> yes
> uhhhhh ... how ' new ' or ' old ' is this
>
> i was under the hard , wrong , delusion , that bash had done this
> differently ..
> while also i thought gawk was doing it wrong
> but gawk says it got it right , $11 being 3
>
> a=( {13..1} ) ; gawk <<<${a[*]} ' { print $11 } '
>
> weird .. i might have suxxed that knowledge from long ago ...
> hmm
>
> greets ! ..
Yes, it helps to keep track of what language one's writing in. :-)
>
>
> On Fri, Sep 27, 2024 at 10:07 AM Andreas Kähäri <andreas.kahari@abc.se>
> wrote:
>
> > On Fri, Sep 27, 2024 at 09:05:47AM +0200, alex xmb sw ratchev wrote:
> > > u talk in bash , or posix mode ? or awk ?
> > >
> > > set {1..13}
> > > echo $11
> > > 11
> >
> > The output here, "11", is the value of the 1st positional parameter with
> > an extra "1" appended to the end.
> >
> > Had you outputted the value of "${11}", you would also have gotten "11",
> > because the value of the 11th positional parameter is "11" (because of
> > the way you set the values of the positional parameters).
> >
> > A better test would have been to set the positional parameters to
> > something other than their ordinal numbers:
> >
> > set -- {a..m}
> >
> > Outputting "$11" would then have given you "a1", while outputting
> > "${11}" would have given you "k". Which of these is the "correct"
> > output depends on what you are trying to do.
> >
> > >
> > > bash
> > >
> > > On Thu, Sep 26, 2024 at 7:16 PM Greg Wooledge <greg@wooledge.org> wrote:
> > > >
> > > > On Thu, Sep 26, 2024 at 18:53:59 +0200, alex xmb sw ratchev wrote:
> > > > > On Thursday, September 26, 2024, Wiley Young <wyeth2485@gmail.com>
> > > wrote:
> > > > > > "${1}"
> > > > > > "$1" is okay
> > > > > > "${11}"
> > > > > > "$11" is an error
> > > >
> > > > > sorry .. where is $11 and error ?
> > > >
> > > > $11 would be equivalent to ${1}1 which is not what's intended.
> >
> > --
> > Andreas (Kusalananda) Kähäri
> > Uppsala, Sweden
> >
> > .
> >
> >
--
Andreas (Kusalananda) Kähäri
Uppsala, Sweden
.
- Re: sed with Variable Substitution in the command, (continued)
- Re: sed with Variable Substitution in the command, Wiley Young, 2024/09/26
- Re: sed with Variable Substitution in the command, alex xmb sw ratchev, 2024/09/27
- Re: sed with Variable Substitution in the command, Andreas Kähäri, 2024/09/27
- Re: sed with Variable Substitution in the command, alex xmb sw ratchev, 2024/09/27
- Re: sed with Variable Substitution in the command,
Andreas Kähäri <=
- Re: sed with Variable Substitution in the command, Greg Wooledge, 2024/09/27
- Re: sed with Variable Substitution in the command, alex xmb sw ratchev, 2024/09/27
- Re: sed with Variable Substitution in the command, alex xmb sw ratchev, 2024/09/27