Mail Archives: cygwin/2007/01/23/11:33:38
--------------enig5BB6CD431C9124C6434E96B0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
The following one liner illustrates a bug in sh:
$ /bin/bash -c '/bin/bash -cx '\''x=3D`echo hello`'\''' > @x
++ echo hello
+ x=3D$'hello\r'
$
The problem is as follows. When a built-in shell command (such as pwd
or echo) is executed within back quotes (or within $(...)) when the
shell's output is redirected to a file, the command produces \r\n at the
end of the line of which only the final \n is removed.
Normally when a command is executed within back quotes, the final line
ending is removed before the result is substituted. That happens here
also, but the difference is that there is still a \r at the end.
When the echo command in the above example is replace by /bin/echo, the
result is correct (i.e. no \r in the assignment to x):
$ /bin/bash -c '/bin/bash -cx '\''x=3D`/bin/echo hello`'\''' > @x
++ /bin/echo hello
+ x=3Dhello
$
The bug, it seems to me, is that the shell checks that its output is
redirected to a file and that it therefore has to write \r\n at the end
of each line. So far so good. However, when it executes a built-in
command within back quotes, it still uses this knowledge and still
writes \r\n.
It may be relevant that I have Cygwin configured to use DOS line
endings. Also, my Cygwin installation is up-to-date (except for pending
updates to readline). My bash version is 3.2.9-10.
--=20
Sjoerd Mullender
--------------enig5BB6CD431C9124C6434E96B0
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iQCVAwUBRbY4xz7g04AjvIQpAQJQNwP+O6MEC2yeJERLPfHrTDHikPidr9tG55jU
MeP2gQ8fJ5o0QAtdPKgKmqtSGxizJCRQM/z7HFYfFXBLJsoj099SLAEBsWXZe9z7
JI4q5o+7g+hIIZBiyZK1llfbjHW5Xd+zsi28u39jQJmX364F6Ov1uCl1Rqs8I2we
W563nRs/whg=
=Cqol
-----END PGP SIGNATURE-----
--------------enig5BB6CD431C9124C6434E96B0--
- Raw text -