在 Wed, 05 Sep 2012 19:57:19 +0800, Thorsten Glaser <[email protected]> 寫道:
Roy dixit:
But MSYS bash did it in same way.
Yes, but this is not GNU bash – one of mksh’s strengths is that
it behaves the same across all platforms.
The following patch works only with CRLF, not
any CR.
It still breaks
cr=$(print \\r)
cr=$(mksh -c 'print \\r')
and possibly, depending on which printf(1) is used,
cr=$(printf \\r)
I leave the patch here so that someone who want to use mksh as MSYS
shell can
be helped.
It’s just that people who write shell scripts for MSYS should
take care to strip the CR off external commands themselves or
switch the stdio into binary mode. (That’s usually not a lot.)
bye,
//mirabilos
Yes, it will break $(print \\r) or $(echo \\015), but it is still worth as
a separated patch for MSYS users.
This patch will really process only CRLF.
Index: eval.c
===================================================================
RCS file: /cvs/src/bin/mksh/eval.c,v
retrieving revision 1.128
diff -u -r1.128 eval.c
--- eval.c 24 Aug 2012 21:16:06 -0000 1.128
+++ eval.c 5 Sep 2012 14:17:57 -0000
@@ -844,7 +844,11 @@
c = '\n';
--newlines;
} else {
+#ifdef __MSYS__
+ while ((c = shf_getc(x.u.shf)) == 0 || c == '\n' || (c == '\r' &&
*(x.u.shf->rp)=='\n'))
+#else
while ((c = shf_getc(x.u.shf)) == 0 || c ==
'\n')
+#endif
if (c == '\n')
/* Save newlines */
newlines++;