At 2019-12-30T17:30:29+0000, Ralph Corderoy wrote: > > - The lone "'" inside the here document inside $() results in > > ./src/roff/groff/tests/on-latin1-device-oq-is-0x27.sh[36]: no closing > > quote > > with ksh. > > I think that's a ksh bug. https://manned.org/ksh.1 can be searched for > `<<' and the entry doesn't suggest quote needs escaping.
Interesting!
> Heirloom sh is happy with it if I replace $() with ``.
Oy vey. That's a cure worse than the disease!
I'll cite the Tom Duff rc paper yet again. If people haven't guessed,
it's one of my favorites.
Bourne also rescans input when doing command substitution. This is
because the text enclosed in back-quotes is not a string, but a
command. Properly, it ought to be parsed when the enclosing command
is, but this makes it difficult to handle nested command
substitutions, like this:
size=`wc -l \`ls -t|sed 1q\``
The inner back-quotes must be escaped to avoid terminating the outer
command. This can get much worse than the above example; the number
of \`s required is exponential in the nesting depth. Rc fixes this
by making the backquote a unary operator whose argument is a
command, like this:
size=`{wc -l `{ls -t|sed 1q}}
No escapes are ever required, and the whole thing is parsed in one
pass.[1]
Note that POSIX's $() is isomorphic to Duff's `{}.
> That's a handy
> unalduterated shell. I don't think POSIX states the single quote
> requires escaping.
> https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_07_04
>
> > So much quoting and escaping is hard to read either way.
>
> I think the printf method can be improved.
>
[Branden's way]
> > -actual=$("$groff" -Tlatin1 <<EOF
> > -.pl 1v
> > -\[oq] = '
> > -EOF
> > -)
> > +actual=$(printf ".pl 1v\n\\\\[oq] = '\n" | "$groff" -Tlatin1)
[Ingo's way]
> $ printf ".pl 1v\n\\\\[oq] = '\n"
> .pl 1v
> \[oq] = '
> $ printf ".pl 1v\n\\\\[oq] = '\n" | sha1sum
> 86c0cab47574a3b6ee5a89d9472d1751ff6f97dc -
[Ralph's way]
> $ printf '%s\n' '.pl 1v' '\[oq] = '\' | sha1sum
> 86c0cab47574a3b6ee5a89d9472d1751ff6f97dc -
I still prefer my here document because it _looks_ like an actual groff
document, and therefore more valuable for pedagogical purposes, but if I
have to give it up, I prefer your printf recipe to Ingo's.
*roff macro writers (like us!) who can count long repeated sequences of
uninterrupted backslashes by eye with ease are to be pitied, not
emulated.
Regards,
Branden
[1] http://doc.cat-v.org/plan_9/4th_edition/papers/rc
signature.asc
Description: PGP signature
