bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nofork command substitution


From: alex xmb ratchev
Subject: Re: nofork command substitution
Date: Fri, 19 May 2023 17:56:10 +0200

hello ..

On Fri, May 19, 2023, 16:29 Chet Ramey <chet.ramey@case.edu> wrote:

> On 5/18/23 10:14 PM, Dale R. Worley wrote:
> > Chet Ramey <chet.ramey@case.edu> writes:
> >> Bash allows the close brace to be joined to the remaining
> >> characters in the word without being followed by a shell metacharacter
> >> as a reserved word would usually require.
> >
> > I had to read this a couple of times to figure out what it means.  In
> > particular "the word" isn't well-bound here.
>
> Command substitution is a word expansion; word expansions are performed on
> words; command substitution occurs as part of a word. That all seems
> self-evident. The only reason to mention it is the quirk required to have
> the close brace act as a reserved word when it is needed to terminate the
> command (you know someone will eventually ask about it).
>

why this

> This text is clear in its description of the behavior but entirely
> > unclear regarding what the point is:
> >
> >> If the first character is a '|', the construct expands to the value of
> >> the 'REPLY' shell variable after COMMAND executes, without removing any
> >> trailing newlines, and the standard output of COMMAND remains the same
> >> as in the calling shell.
>
> What's mysterious about it? If you don't want to have to output text as
> the value of the command substitution, you can simply assign arbitrary
> data to REPLY. The bonus is that the trailing newlines are preserved, a
> common question about standard command substitution.
>

very good
1:1 data is upper depend

> My guess is that the intention is for COMMAND to be "read" with no
> > names:
>
> Not necessarily. The example shows a simple assignment to REPLY.
>
> > Also, can you clarify the semantics on this point:  The text above says
> > "the construct expands to the value of the 'REPLY' shell variable after
> > COMMAND executes, without removing any trailing newlines".  However, the
> > documentation of "read" says:  "If no names are supplied, the line read,
> > without the ending delimiter but otherwise unmodified, is assigned to
> > the variable REPLY."
>
> The two uses are unrelated.
>
> > So the sequence of processing is:  read inputs a line; read deletes the
> > ending newline and assigns the remainder to REPLY; command substitution
> > obtains the value of REPLY (which does not contain a newline); command
> > substitution returns that value "without removing any trailing
> > newlines".
> >
> > Is that what you intend the code to do/what the code does?
>
> No. I mean, if you want to use `read' in that way, you certainly can, but
> that's not going to be the common case.
>
> Chet
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>
>
>


reply via email to

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