This is the mail archive of the cygwin 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]
Other format: [Raw text]

Re: bash-3.1-7 BUG

mwoehlke <mwoehlke <at>> writes:

> > Would it be possible to do this dynamically (instead of keying off of 
> > mounts, etc.): if the first line of the file read by bash has a \r\n, 
> > use text-mode (1-char-at-a-time) semantics, else use binary semantics 
> > (lseek)?
> I hate to say this, but... if bash goes this route, could it be a shopt? 
> I would rather know that my scripts are broken (DOS-format).

Thanks for the ideas; here's what I'll try.  Bash does indeed already scan the 
first line (I'm not sure if it is line or first 80 characters or what it is 
exactly, but I do know it scans) to see if it detects any NUL bytes, at which 
point it complains the file is binary and not a script.  So I can probably hack 
that scan to also look for \r.  So first I will open the file according to the 
mount point rules.  If the file is text mode, perform the scan in binary mode, 
and if any \r is seen, revert to text mode and no lseeks.  If the scan in 
binary mode succeeds, then leave the file in binary mode, assuming that the 
file is unix format even though it is on a text mount, and that lseeks will 
work.  If the file starts life binary mode (ie. was on a binary mount), skip 
the check for \r in the scan (under the assumption that on a binary mount, \r 
is intentional and not a line ending to be collapsed), and use lseeks.  No 
guarantees on whether this will pan out, or be bigger than I thought, but 
hopefully you will see a bash 3.1-8 with these semantics soon.

Eric Blake

Unsubscribe info:
Problem reports:

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