This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

CR/LF translation


Hi,

I have a problem with end-of-line characters in a bash script.  I'd
appreciate any suggestions or information you can provide.

In summary, I'm getting different behavior from this script based on whether
I process a NT text file or a Cygwin (vim) text file.  I read somewhere that
Cygwin did the end-of-line character translation automatically, but
apparently not.  I don't have CYGWIN=binmode set.  I saw an option in
Cygwin's setup.exe for default file type, DOS vs Unix.  I have installed
both ways and seen the same behavior. I uninstalled everything using
setup.exe between installs.

Here's the bash script:
	#!bash
	list=`cat $1`
	for word in $list;
		do
			echo List item is ${word}END-OF-LINE
	done

Here's the input file (indented) created by concatenating a file created in
notepad (3 lines) onto the end of a file created with vim (3 lines) using
cat:
	this
	is
	unix
	this
	is
	notepad

Here's the output on my test file (indented):
	List item is thisEND-OF-LINE
	List item is isEND-OF-LINE
	List item is unixEND-OF-LINE
	END-OF-LINEs this
	END-OF-LINEs is
	END-OF-LINEs notepad


So the last three lines are mangled, apparently by a carriage return
character.  It seems fairly clear that notepad put in a CR character which
is not being stripped by cat.  I can fix this with a dos2unix utility I
downloaded, but it would be more convenient not to have to do this.  What's
wrong with my setup?

Here are the relevant versions:
	bash 2.04-1
	cygwin 1.1.4

Thanks in advance,
Ryan Seghers


PS.  Here's a bonus question.  I tried to write my own dos2unix.  So I wrote
a dump program in Visual C++ without any special includes or links (not
linking any cygwin DLLs as far as I know).  I wanted to see what the codes
were for the end-of-line characters so I could strip them.  When I run my
dump from a NT Command Prompt on the text file, I see no difference between
the first three lines and the last three lines.  All the lines are
terminated by a single character, int 10!?  So my dump program isn't showing
the CR character.  Is my dump program build picking up a cygwin DLL or
something?

Here's the source:
	//
	// read the file
	//
	char c;
	while(!feof(fd))
	{
		c = getc(fd);
		if (c != -1)


			printf("c (int) = %d\n", c);
		}
	}







--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]