X-Spam-Check-By: sourceware.org Message-ID: <4574F5FF.1050804@byu.net> Date: Mon, 04 Dec 2006 21:30:55 -0700 From: Eric Blake User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Thunderbird/1.5.0.8 Mnenhy/0.7.4.666 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: bash CRLF problems (I have read the recent announcement) References: <7794 DOT 1165273150 AT gemini DOT franz DOT com> In-Reply-To: <7794.1165273150@gemini.franz.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Kevin Layer on 12/4/2006 3:59 PM: > I'm really perplexed by the following behavior: > > rfr AT mad64 ~ > $ cat -v foo1.sh > echo 8010 > foo1.out > > rfr AT mad64 ~ > $ cat -v foo2.sh > sh foo1.sh > version=`cat foo1.out` The result of `` comes from a pipe instead of a disk file, and only disk files are affected by text mode mounts, so command substitution can only strip \r if igncr is set. cat reads its inputs in binary (at one point, cat used to read in text mode by default, unless you passed --binary, but the upstream maintainer removed that on the ground that POSIX requires binary behavior from cat). I could consider adding cat --text to cygwin's cat, but it would be cygwin-only, so you would not be very portable in using it. However, instead of spawning two processes to assign your variable (a subshell for ``, then cat), you could try this instead, with several benefits - bash opens the file in text mode, the variable assignment is faster due to fewer processes, and the line does not rely on any cygwin-specific extensions: read version < foo1.out Another thing you could do is avoid putting line endings in foo1.out in the first place - either use 'echo -n 8081 > foo1.out', 'echo -e 8081\\c > foo1.out' (both of which rely on unportable usage of echo), or 'printf 8081 > foo1.out' (portable to POSIX sh, but not all platforms conform to POSIX yet). A patch along this line was just submitted to autoconf, in its use of files containing results of runtime programs. > $ mount > C:\cygwin\bin on /usr/bin type system (textmode) Asking for problems. Usually, it is safer if you limit textmode mounts to the directories that contain your files, rather than globally making the basic cygwin files text mode. > > The bug, IMO, is the assigment to version of `cat foo1.out` contains a > ^M. I'm on a text mount, so this is counter to what I thought would > happen. Again, based on the POSIX wording, cat must operate on binary files, so it opens in binary mode by default, even on text mounts. Which means the command substitution sees the \r. You can also play with CYGWIN=nobinmode to turn pipes into text mode, so that the command substitution never sees the \r, but that has other odd effects, such as breaking 'tar xjf foo.tar.bz2'. > > I experimented with `igncr' and couldn't get it to work. Examples of what you tried? - -- Life is short - so eat dessert first! Eric Blake ebb9 AT byu DOT net volunteer cygwin bash maintainer -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFdPX+84KuGfSFAYARApzLAKCh46ov7l9hLZsPnrpw13K1T2JWBgCeOqFb EkIlGw93EAndVHNyzKA+Zaw= =fyM1 -----END PGP SIGNATURE----- -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/