[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 13:36:44 +0200 |
'C ..'
' ..'
'| ..'
.. i dont get it
On Mon, May 15, 2023, 19:35 Chet Ramey <chet.ramey@case.edu> wrote:
> The latest devel branch push has the initial implementation of `nofork'
> command substitution. The excerpt from the info manual describing it is
> appended.
>
> Please test it out, and find the places I missed. Thanks.
>
> Chet
>
> ==========
> There is an alternate form of command substitution:
>
> ${C COMMAND; }
>
> which executes COMMAND in the current execution environment. This means
> that side effects of COMMAND take effect immediately in the current
> execution environment and persist in the current environment after the
> command completes (e.g., the 'exit' builtin will exit the shell).
>
> The character C following the open brace must be a space, tab,
> newline, '(', or '|', and the close brace must be in a position where a
> reserved word may appear (i.e., preceded by a command terminator such as
> semicolon). 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.
>
> This type of command substitution superficially resembles executing
> an unnamed shell function: local variables are created as when a shell
> function is executing, and the 'return' builtin forces COMMAND to
> complete; however, the rest of the execution environment, including the
> positional parameters, is shared with the caller.
>
> If the first character following the open brace is a '(', COMMAND is
> executed in a subshell, and COMMAND must be terminated by a ')'. This
> is similar to the '(' compound command (*note Command Grouping::). 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. Bash creates 'REPLY' as an initially-unset
> local variable when COMMAND executes, and restores 'REPLY' to the value
> it had before the command substitution after COMMAND completes, as with
> any local variable.
>
> For example, this construct expands to '12345', and leaves the shell
> variable 'X' unchanged in the current execution environment:
>
> ${ local X=12345 ; echo $X; }
>
> (not declaring 'X' as local would modify its value in the current
> environment, as with normal shell function execution), while this
> construct does not require any output to expand to '12345':
>
> ${| REPLY=12345; }
>
> and restores 'REPLY' to the value it had before the command
> substitution.
>
> --
> ``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/
>
>
- Re: nofork command substitution, (continued)
- Re: nofork command substitution, Robert Elz, 2023/05/19
- Re: nofork command substitution, alex xmb ratchev, 2023/05/19
- Re: nofork command substitution, alex xmb ratchev, 2023/05/19
- Re: nofork command substitution, Chet Ramey, 2023/05/22
- Re: nofork command substitution, Martijn Dekker, 2023/05/22
Re: nofork command substitution, Chet Ramey, 2023/05/19
Re: nofork command substitution,
alex xmb ratchev <=
Re: nofork command substitution, Chet Ramey, 2023/05/19
Re: nofork command substitution, Grisha Levit, 2023/05/19
Re: nofork command substitution, Koichi Murase, 2023/05/23