From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8044 invoked by alias); 26 Apr 2012 14:14:15 -0000 Received: (qmail 7995 invoked by uid 22791); 26 Apr 2012 14:14:13 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from plane.gmane.org (HELO plane.gmane.org) (80.91.229.3) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Apr 2012 14:13:58 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SNPSG-0001tq-HO for cygwin@cygwin.com; Thu, 26 Apr 2012 16:13:56 +0200 Received: from rrcs-74-62-25-170.west.biz.rr.com ([74.62.25.170]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 26 Apr 2012 16:13:56 +0200 Received: from Andrew by rrcs-74-62-25-170.west.biz.rr.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 26 Apr 2012 16:13:56 +0200 To: cygwin@cygwin.com From: Andrew DeFaria Subject: Odd behavior of scripts in dos mode Date: Thu, 26 Apr 2012 14:14:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120309 Thunderbird/11.0 X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2012-04/txt/msg00594.txt.bz2 I remember that Cygwin used to not be able to run scripts that were converted or were in "DOS" mode - had trailing carriage returns in the file. It would fail because the #! line might have /bin/bash\r which was not a file (bash with a carriage return that is). But the behavior has changed. Now it seems to ignore the trailing carriage return and it execs bash itself. But it fails later on with other carriage returns. For example, consider the following: #!/bin/bash if [ 1 = 1 ]; then echo "test" fi Then use unix2dos to make the file have trailing carriage returns and execute the script: Neptune:test.sh ./test.sh: line 2: $'\r': command not found ./test.sh: line 6: syntax error: unexpected end of file Cygwin used to say something like "Unable to exec /bin/bash" but now it execs /bin/bash and bash fails to execute the if statement. So it seems to me that Cygwin is trying to be nice and solve the problem of people who get their scripts edited in some tools that writes out DOS mode files. My question is if it strips the trailing carriage return from the #! line why doesn't it do it for all lines? (And yes I know I can dos2unix the script and it will work - the problem is it coming from some SCM system checkout (perforce) and that tool is adding trailing carriage returns to the file when it checks it out). -- Andrew DeFaria Why is it that the guy who comes up behind you while you're waiting for an elevator presses the already lit button as though he has some magical powers that you don't? -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple