On Mar 23, 2017 10:16 AM, Martijn Dekker <mart...@inlv.org> wrote: > Op 23-03-17 om 15:44 schreef Dan Douglas: > > On 03/23/2017 04:49 AM, Jean Delvare wrote: > >> Apparently it requires a more recent version of mksh than we are > >> shipping: > > > > Herestrings are old. Should work in just about any ksh. > pdksh (including OpenBSD ksh) doesn't have them.
Ew > On those (as on POSIX), you need a here-document to get the same effect: > > while stuff; do > stuff > done <<EOF > $(cmd) > EOF > > >> $ echo $KSH_VERSION @(#)MIRBSD KSH R50 2014/06/29 openSUSE $ > >> ./test_return.sh ./test_return.sh[10]: syntax error: '(' > >> unexpected > >> > >> But indeed works find with the latest upstream version, thanks > >> for the pointer. > > > > It's also not at all equivalent to a pipe. The shell reads the > > command output from a pipe, stripping trailing newlines, and dumps > > the result into a temporary file, which then adds a trailing > > newline, then reads the file back into whatever runs in the loop. > > In most use cases, that seems like a distinction without a difference. It matters when there are zero, or more than one newlines at the end. Besides that, it just has no advantage over `out=$(cmd); printf %s -- "$out" | ...', or better, `read -rd "" out' to avoid mangling the data. In all cases we can't begin processing the loop until we've read the entire possibly large output, so I don't suggest that method unless the intention is to take advantage of its side-effects. > > It will also fail if it expands to more than one word due to lack > > of quotes. (That likely caused your error) > > That is true on bash, but not on mksh. I should probably have added > the quotes anyway though, just to avoid that confusion. I like that feature. Exclusive to mksh though.