public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: cygwin@cygwin.com
Subject: Re: bash-4.3.33-1 fails to execute shell script with CR+LF EOL in text-mounted directory
Date: Thu, 26 Mar 2015 19:05:00 -0000	[thread overview]
Message-ID: <55142BC5.4080209@redhat.com> (raw)
In-Reply-To: <20150326153734.60517.qmail@mx.akamoz.jp>

[-- Attachment #1: Type: text/plain, Size: 2851 bytes --]

On 03/26/2015 09:37 AM, smith@cygwin.akamoz.jp wrote:
> Dear Cygwin developers:
> 
>  It seems that bash-4.3.33(1) handles CR+LF end-of-line in 
> the shell-script incorrectly, all of the following conditions are met:
> 
> a. the shell-script file is on TEXT-MOUNTED directory,

Thanks for the report.  I'll have to test this and see if I can spot
what is going wrong (I don't normally try text-mount directories).

> b. end-of-line style of the file is CR+LF, and

Are you absolutely sure that you don't have excess CR in your file?
text mounts only treats the CRLF as a single newline, but does not eat
lone CR elsewhere in the file.

> c. the command in the file includes & (exec-background),
>    $( ), or `` (command substitutions)
> 
> It works:
> d. it is on the binary-mounted directory, and with igncr shell-option,

Does igncr make a difference in the text mount directory situation?

> e. end-of-line style is LF, or

Yeah, if you don't have CR, it doesn't matter whether you are text mount
or binary mount.  It is only CR that chokes bash, and only if you don't
do something like igncr or text mount to hide it.

> f. condition c is not met. It seems that &&, | and || work fine,
>    although I didn't try all of the metachacters and control-constructs.

Weird.

> 
>  I found it on x86 Cygwin with 64bit Windows environment first,
> the same behavior is observed on 32bit Windows environment also.
> I've not tried yet on x64 Cygwin with 64bit Windows environment.
> 
> shell-script to test: (WITH CR+LF END-OF-LINE STYLE)
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
> #!/bin/bash

Please ATTACH the script as a binary file, rather than pasting it inline
in your email; or at a bare minimum, show 'od -tx1z yourscript' to make
it obvious the exact byte patterns your file contains.  Inline text in
email does NOT make it obvious what line endings you are intending.
> 
> example of execution, on bash-4.3.33(1):
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
> $ LANG=C ./test.sh
> hoge
> ./test.sh: line 3: fuga: command not found
> ./test.sh: line 4: piyo: command not found
> ./test.sh: line 5: o: command not found
> ./test.sh: line 6: ho: command not found
> ./test.sh: line 7: cho: command not found
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
> 
> Maybe commands are read from the positions one-byte shifted, line-by-line.

Use of & or $() causes bash to fork; maybe the forked child is
attempting to lseek back to the position last visited by the parent
based on characters read, but failing to account for the fact that lseek
on a text-mount file causes issues because characters read is different
than file offset advanced?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-03-26 15:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-26 15:38 smith
2015-03-26 19:05 ` Eric Blake [this message]
2015-03-27 20:00 ` smith
2015-09-24 21:09 ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55142BC5.4080209@redhat.com \
    --to=eblake@redhat.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).