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.

  • does POSIX m... Christoph Anton Mitterer via austin-group-l at The Open Group
    • Re: doe... Geoff Clare via austin-group-l at The Open Group
      • Re:... Christoph Anton Mitterer via austin-group-l at The Open Group
        • ... Geoff Clare via austin-group-l at The Open Group
          • ... Harald van Dijk via austin-group-l at The Open Group
            • ... Chet Ramey via austin-group-l at The Open Group
              • ... Harald van Dijk via austin-group-l at The Open Group
                • ... Chet Ramey via austin-group-l at The Open Group
                • ... Chet Ramey via austin-group-l at The Open Group
                • ... Christoph Anton Mitterer via austin-group-l at The Open Group
                • ... Harald van Dijk via austin-group-l at The Open Group

Reply via email to