[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GNUism in groff tests
From: |
G. Branden Robinson |
Subject: |
Re: GNUism in groff tests |
Date: |
Tue, 31 Dec 2019 16:34:56 +1100 |
User-agent: |
NeoMutt/20180716 |
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
- Re: pic anomalies, (continued)
- Re: pic anomalies, Ingo Schwarze, 2019/12/27
- Re: pic anomalies, Eric S. Raymond, 2019/12/27
- Re: pic anomalies, Ingo Schwarze, 2019/12/29
- Re: pic anomalies, Colin Watson, 2019/12/29
- Re: pic anomalies, Larry McVoy, 2019/12/29
- Re: pic anomalies, Ingo Schwarze, 2019/12/30
- Re: pic anomalies, Colin Watson, 2019/12/30
- GNUism in groff tests, was: pic anomalies, Ingo Schwarze, 2019/12/30
- Re: GNUism in groff tests, Ingo Schwarze, 2019/12/30
- Re: GNUism in groff tests, Ralph Corderoy, 2019/12/30
- Re: GNUism in groff tests,
G. Branden Robinson <=
- Re: GNUism in groff tests, Ralph Corderoy, 2019/12/31
- Re: GNUism in groff tests, Ingo Schwarze, 2019/12/31
- Re: GNUism in groff tests, Colin Watson, 2019/12/30
- Re: GNUism in groff tests, G. Branden Robinson, 2019/12/31
- Re: GNUism in groff tests, Ingo Schwarze, 2019/12/31
- Re: GNUism in groff tests, was: pic anomalies, John Gardner, 2019/12/30
- Re: GNUism in groff tests, was: pic anomalies, Larry McVoy, 2019/12/30
- Re: GNUism in groff tests, was: pic anomalies, G. Branden Robinson, 2019/12/31
- Re: GNUism in groff tests, was: pic anomalies, Ralph Corderoy, 2019/12/31
- Re: GNUism in groff tests, was: pic anomalies, Ralph Corderoy, 2019/12/31