bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling files with CRLF line ending


From: Chris Elvidge
Subject: Re: Handling files with CRLF line ending
Date: Wed, 7 Dec 2022 12:38:35 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Lightning/5.4

On 06/12/2022 23:39, L A Walsh wrote:
On 2022/12/06 10:57, Chris Elvidge wrote:
Yair, how about using the Python installed in the WSL instance.
---
    Oh, I wondered why Python used CRLF, but nothing else did.

    What version of python are you using?  The Python for WSL,
the python for cygwin, or the python for Windows?  If you are
using python for Windows, I'd *sorta* expect it to use CRLF, but
would expect WSL or Cygwin versions to use just 'LF'.  Similarly w/bash --
I haven't tested it, but I'd expect bash compiled for windows
(using mingw toolchain) to use CRLF, but LF for WSL or Cygwin.

Are you using both tools for the same OS and subsys and having
them conflict?





I don't use Python generally, but my understanding of it (only a quick test)

f = open("demofile2.txt", "a")
f.write("Now the file has more content!")
f.close()

f.write doesn't append either \r\n or \n unless specified.

f.write("Now the file has more content!\n") does, in Windows, seem to append \r\n. In Linux (Slackware) and WSL (Slackware), it only appends \n.

So it does seem to be a "problem" with Windows rather than a problem with Python.

However, I may be wrong!!

Reading the file created in Python/Windows with bash read in linux:
read <demofile2.txt
echo $REPLY | hexdump -c
0000000   N   o   w       t   h   e       f   i   l   e       h   a   s
0000010       m   o   r   e       c   o   n   t   e   n   t   !   N   o
0000020   w       t   h   e       f   i   l   e       h   a   s       m
0000030   o   r   e       c   o   n   t   e   n   t   !   N   o   w
0000040   t   h   e       f   i   l   e       h   a   s       m   o   r
0000050   e       c   o   n   t   e   n   t   !   N   o   w       t   h
0000060   e       f   i   l   e       h   a   s       m   o   r   e
0000070   c   o   n   t   e   n   t   !  \r  \n
000007a

read -d $'\r' <demofile2.txt
echo $REPLY | hexdump -c
0000000   N   o   w       t   h   e       f   i   l   e       h   a   s
0000010       m   o   r   e       c   o   n   t   e   n   t   !   N   o
0000020   w       t   h   e       f   i   l   e       h   a   s       m
0000030   o   r   e       c   o   n   t   e   n   t   !   N   o   w
0000040   t   h   e       f   i   l   e       h   a   s       m   o   r
0000050   e       c   o   n   t   e   n   t   !   N   o   w       t   h
0000060   e       f   i   l   e       h   a   s       m   o   r   e
0000070   c   o   n   t   e   n   t   !  \n
0000079

Mapfile seems to work similarly.



--
Chris Elvidge
England




reply via email to

[Prev in Thread] Current Thread [Next in Thread]