Summary: | /bin/sh: false expansion | ||
---|---|---|---|
Product: | Base System | Reporter: | Steffen Nurpmeso <steffen> |
Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> |
Status: | New --- | ||
Severity: | Affects Only Me | CC: | jilles, lwhsu |
Priority: | --- | ||
Version: | 12.1-STABLE | ||
Hardware: | Any | ||
OS: | Any |
Description
Steffen Nurpmeso
2020-12-12 00:28:54 UTC
Given the standard as modified by https://www.austingroupbugs.net/view.php?id=1123 I see insufficient reason to change this, also to avoid POLA issues with people trying to swap via a=$b b=$a. Sorry for being too terse. It was just a simplemost reproducer without any further comments. Sorry. #?2|kent$ for s in dash bash mksh bosh; do $s -c 'du=ich wir='"'"'hey '"'"'$du; echo $wir'; done hey ich hey ich hey ich hey ich Hmmmm. Since issue 1123 is possibly not, you surely mean instead 75501 Variable assignments shall be performed as follows: 75502 • If no command name results, variable assignments shall affect the current execution 75503 environment. 75504 • If the command name is not a special built-in utility or function, the variable assignments 75505 shall be exported for the execution environment of the command and shall not affect the 75506 current execution environment except as a side-effect of the expansions performed in step 75507 4. In this case it is unspecified: 75508 — Whether or not the assignments are visible for subsequent expansions in step 4 75509 — Whether variable assignments made as side-effects of these expansions are visible for 75510 subsequent expansions in step 4, or in the current shell execution environment, or 75511 both where 4 is 5495 4. Each variable assignment shall be expanded for tilde expansion, parameter expansion, 75496 command substitution, arithmetic expansion, and quote removal prior to assigning the 75497 value. So .. this very exact behaviour is unspecified? If that is really true (i personally have hard times with standard texts), this issue can very well be closed. (FreeBSD sh is alone with this exact behaviour as far as i know, still..) I think you are right; the formulation "Each variable assignment shall be expanded prior to assigning the value" is not compatible with our behaviour to expand everything before assigning anything. On the other hand, a=$b b=$a U where U is not empty and neither a special builtin nor a function can still place swapped values in the utility environment (although it is not required to). Sorry for being so late, i wanted to reread the standard text, maybe to open an issue. But i think your last statement pretty much describes the situation. (Whereas my initial report was only "from gut".) 3385 4.23 Variable Assignment 3386 In the shell command language, a word consisting of the following parts: 3387 varname=value 3388 When used in a context where assignment is defined to occur and at no other time, the value 3389 (representing a word or field) shall be assigned as the value of the variable denoted by varname. 3390 Note: For further information, see XCU Section 2.9.1 (on page 2365). --- 75482 2.9.1 Simple Command 75495 4. Each variable assignment shall be expanded for tilde expansion, parameter expansion, 75496 command substitution, arithmetic expansion, and quote removal prior to assigning the 75497 value. --- 75501 Variable assignments shall be performed as follows: 75502 • If no command name results, variable assignments shall affect the current execution 75503 environment. --- So everything should be handled sequentially, making it a bug. --- 75504 • If the command name is not a special built-in utility or function, the variable assignments [.] 75507 4. In this case it is unspecified: 75508 — Whether or not the assignments are visible for subsequent expansions in step 4 75509 — Whether variable assignments made as side-effects of these expansions are visible for 75510 subsequent expansions in step 4, or in the current shell execution environment, or 75511 both --- So it allows to setup the "execution environment of the command" entirely from the current environment, which is effectively read-only. As you say. |