Hey. Perhaps someone can help me with this.
Many areas in the shell are defined to work with text or lines of text (i.e. containing a trailing newline). For command substitution the standard says: "The shell shall expand the command substitution by executing command in a subshell environment (see Shell Execution Environment) and replacing the command substitution (the text of command plus the enclosing "$()" or backquotes) with the standard output of the command, removing sequences of one or more <newline> characters at the end of the substitution." It's anyway clear that any trailing newlines get stripped. My question is rather, does the final line of the commands standard output need to have a trailing newline to be recognised? In other words, if the stdout would be as follows: printf 'abc\nxyz' would a (weird) shell be free to choose to only substitute 'abc', since 'xyz' is not newline-terminated... but still be conforming in the sense of POSIX? My interpretation of the above quote from the standard would be: no, a conforming shell needs to capture the whole stdout (except for trailing newlines), so the result would need to be the full 'abc\nxyz'. Thanks, Chris.
