X-Spam-Check-By: sourceware.org Message-ID: <45B638BE.80003@acm.org> Date: Tue, 23 Jan 2007 17:33:02 +0100 From: Sjoerd Mullender User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: bug with built-in commands in bash when redirecting output Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig5BB6CD431C9124C6434E96B0" Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------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--