public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Odd behavior of scripts in dos mode
@ 2012-04-26 14:14 Andrew DeFaria
  2012-04-26 14:26 ` Earnie Boyd
  2012-04-26 14:41 ` Eric Blake
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew DeFaria @ 2012-04-26 14:14 UTC (permalink / raw)
  To: cygwin

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 <http://defaria.com>
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-04-26 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-26 14:14 Odd behavior of scripts in dos mode Andrew DeFaria
2012-04-26 14:26 ` Earnie Boyd
2012-04-26 14:33   ` Andrew DeFaria
2012-04-26 16:07   ` Buchbinder, Barry (NIH/NIAID) [E]
2012-04-26 14:41 ` Eric Blake
2012-04-26 17:22   ` Andrew DeFaria

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).