Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 523874 - sys-apps/man-1.6g uses non-portable `echo \n`
Summary: sys-apps/man-1.6g uses non-portable `echo \n`
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: nonbash
  Show dependency tree
 
Reported: 2014-09-27 13:04 UTC by Alex Xu (Hello71)
Modified: 2015-05-08 03:22 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Xu (Hello71) 2014-09-27 13:04:06 UTC
man pages are rendered with no footers and end in "(nlu+10" (no quotes).

tested with app-shells/dash-{0.5.7.3-r1,0.5.7.4}.

tried strace -ffe execve but the only "suspicious" command line (with subshells and pipes) had the same effect when executed separately (tested with diff).
Comment 1 Alex Xu (Hello71) 2014-10-03 11:25:01 UTC
s/had the same effect/rendered correctly/
Comment 2 Joshua Kinard gentoo-dev 2014-10-04 02:09:34 UTC
Ditto on my machine.  Looks like this forum thread covers it:
https://forums.gentoo.org/viewtopic-p-6185879.html?sid=4ec5e1a658d061ea0e522623f38f702b#6185879

> [Edit]
> I figured out what was wrong: I'd been messing around with linking
> /bin/sh on that machine to /bin/dash, and for whatever reason that command
> printed by man -d has a "\n" that gets interpreted differently in bash. And
> of course /usr/bin/man has "sh" hardcoded into it...
> 
> But it's all fixed now - I just installed man-db instead and that doesn't
> have any problems.

If you execute "man -d man" from that thread, this is where the "(nlu+10" bit is specified at:

man:
not executing command:
  (cd "/usr/share/man" && (echo ".ll 17.5i"; echo ".nr LL 17.5i"; echo ".pl 1100i"; /bin/bzip2 -c -d '/usr/share/man/man1/man.1.bz2'; echo ".\\\""; echo ".pl \n(nlu+10") | /usr/bin/gtbl | /usr/bin/nroff -mandoc | /usr/bin/less)

So it apparently hinges on how dash and bash interpret \n's, based on that thread anyways.  Going on that, I ran the following command from the above string in both bash and dash:

(echo ".ll 17.5i"; echo ".nr LL 17.5i"; echo ".pl 1100i"; /bin/bzip2 -c -d '/usr/share/man/man1/man.1.bz2'; echo ".\\\""; echo ".pl \n(nlu+10")

Put each output into text files, and then diffed them, and this is what I get:

--- x-bash  2014-10-03 22:05:26.799921399 -0400
+++ x-dash  2014-10-03 22:05:36.139921344 -0400
@@ -530,5 +530,6 @@ Federico Lucifredi <flucifredi@acm.org>
 .SH "SEE ALSO"
 apropos(1), whatis(1), less(1), groff(1), man.conf(5).
 .\"
-.pl \n(nlu+10
+.pl
+(nlu+10

dash appears to interpret the \n inside the double quotes whereas bash doesn't.  I tried escaping that one \n to get dash to behave like bash, which appears to work, but then bash will output the \n incorrectly.

Not sure what a good solution is here...
Comment 3 Joshua Kinard gentoo-dev 2014-10-04 02:30:50 UTC
Seems the 'echo' calls need to become 'printf' calls instead:
http://shebang.brandonmintern.com/bourne-is-not-bash-or-read-echo-and-backslash/

And:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=613473

> Hi, I'm not sure what you are after.  dash implements POSIX
> ieee1003.1-2004, and Debian policy; it implements some XSI extension.
> AFAICS the behavior of dash's echo is just fine with these standards.
> 
> Yes, using echo isn't portable, posix says
> "It is not possible to use echo portably across all POSIX systems unless
> both -n (as the first argument) and escape sequences are omitted.
> 
> The printf utility can be used portably to emulate any of the
> traditional behaviors of the echo utility"...

I am not sure where the full 'man' command is being assembled from (from the man -d output in my previous comment), but likely, that behavior of using 'echo' would need to be changed to 'printf'.  Where that change is needed, and whether that's something we want to actually implement, I am not sure about.
Comment 4 Alex Xu (Hello71) 2015-05-08 01:47:58 UTC
seems to work now on dash 0.5.8.2, groff 1.22.3, man 1.6g?
Comment 5 SpanKY gentoo-dev 2015-05-08 03:05:30 UTC
the source is still broken:
src/man.c:      strcat(buft, "; echo \".\\\\\\\"\"; echo \".pl \\n(nlu+10\"");

two echos or a printf should fix it easy enough.  it's just that man is a lower priority now that most people have switched to man-db.
Comment 6 SpanKY gentoo-dev 2015-05-08 03:22:08 UTC
should be all set now in the tree; thanks for the report!

Commit message: Avoid escape sequences with `echo`
http://sources.gentoo.org/sys-apps/man/files/man-1.6g-echo-escape.patch?rev=1.1
http://sources.gentoo.org/sys-apps/man/man-1.6g-r1.ebuild?rev=1.1