Christoph Anton Mitterer wrote, on 25 Jan 2022: > > 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'.
You are correct, and a common method of preserving trailing newlines is to append a non-newline character and then strip it, e.g.: output=$(some_command && printf x) output=${output%x} -- Geoff Clare <g.cl...@opengroup.org> The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England