[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: |
Thu, 26 Sep 2024 20:40:27 +0200 |
On Thu, Sep 26, 2024 at 02:21:06PM -0400, Greg Wooledge wrote:
> On Thu, Sep 26, 2024 at 20:03:10 +0200, Andreas Kähäri wrote:
> > On Thu, Sep 26, 2024 at 01:16:21PM -0400, Greg Wooledge wrote:
>
> > > > On Thursday, September 26, 2024, Wiley Young <wyeth2485@gmail.com>
> > > > wrote:
> > > > > "${1}"
> > > > > "$1" is okay
> > > > > "${11}"
> > > > > "$11" is an error
>
> > > $11 would be equivalent to ${1}1 which is not what's intended.
> >
> > How do you know it's not intended? ;-) "Intention" is not something that
> > can be inferred from the syntax of small fragment of a shell script.
>
> In this case, what we were given by Wiley Young is not a shell script.
> It's a document. The document shows shell syntax in one column, and
> gives an explanation or comment in the second column.
>
> The document is telling us that there is a difference between "${11}"
> and "$11". One is right, and the other is an error.
>
> The context of Wiley's post was "when are braces required, and when are
> they optional". ${1} is a case where the braces are optional, while
> ${11} is a case where they are required.
>
> There is no ambiguity here. The intent is completely clear.
There was never an intention stated in the text, as far as I can see.
I'm saying that "$11" is not an error, if what you want is to is the
value of the first positional parameter cancatenated by the string "1"
(which is a completely valid thing to want). If that is the intention,
then "$11" is correct, and "${11}" is an error.
If your intention is to get the value of the 11th positional parameter,
then you should use "${11}". However, it was never stated what the
intention was, only that "${11}" was "correct" and "$11" was an "error"
("unintended effects will occur").
You simply can't say that "$11" is an error without knowing what the
rest of the code is supposed to do.
--
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, 2024/09/27
- 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