help-bash
[Top][All Lists]
Advanced

[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 10:07:11 +0200

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

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]