X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CC383858431
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1680768230;
	bh=t37aViiN9aGp/DraqV74aqHDQYLRAkZCt8OELn2luWc=;
	h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
	 From;
	b=NvKCdlnXkurAf/TZcW7h3lAezQm0WQXeSAPzYJxHFMycTESE3CWnUxDFz/o6HH9qE
	 VA+kgT8itc/t+LFTqn+YsBEHdwotazmWftwRImEJLMn7H2+F3Vj+Td5WFDSZGt7Um6
	 WGildAnmH8fQRqol+dtXIPZLmz9OxocnXvni1WQA=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF41F3858D32
Date: Thu, 6 Apr 2023 10:03:23 +0200
To: cygwin@cygwin.com
Subject: Re: bash shell script: recently running, now failing
Message-ID: <ZC58y18KZCSQOnP9@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <DB6P18901MB005559D81FD4125B0D6DAA07A4919@DB6P18901MB0055.EURP189.PROD.OUTLOOK.COM>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <DB6P18901MB005559D81FD4125B0D6DAA07A4919@DB6P18901MB0055.EURP189.PROD.OUTLOOK.COM>
X-Provags-ID: V03:K1:pEneop/GmZmYQ/RXaoWL8z9vgmBPVaBeGtntlXlug7AbvQMzmdw
 VnsNF+d8Jb55ZAAgmG/6mfq29Ov1bBd1VqbAfIx2ZWPLC/uD+B+uknys9o9WWcDVdogd5iw
 yolyInHL1CM4FZLr73WKwFmluDx1SUu9KjCLCorm0NlnRcLDfv5hEjiBAtTpjv888fUc/RE
 faL0kCX4MDo293Shz1ldg==
UI-OutboundReport: notjunk:1;M01:P0:tuCn2Bmj8EA=;pcaNkc6CivUIAkOM+SLQcfja/AD
 I+sRvFHNRt0P4IsVUFIrPLBgmAgtY0mUbjSlk6sAxyVewz5JumWOSljbyFGwJ4huw8Ar7RaMO
 wwTFNWw1bNdGxnpcOTHtAToCySWWlZdBQCVC+gPmhJCJAlRd2it9MeE/OIAwZWZKCaOvItcSG
 VEXhNDjhnQnn6lpaG2+nIpvZi7kqYEYsJmXKhz18hcp/me6nMebEnFDuMnsK0LXG5/m/xy/z8
 k2XEG9JXBBlVn6Kkg0mayybBzrMUcKDUPIyXtrZG36NNMsruU8edqRy9/sPVBMvJb2JYwdV+a
 AmsvnNPUiFKlWRh4spBKkfv25y0QqSYDCfPTZNVbrbX7O5nJrNp05tlxY7ABE6ThOerItFbce
 zKRYDMEJOBzoICDIGEpywjXBvRsCvU1loI+rRWgluUlgNWnh1cc3832chYWaMOgsJ8wOHXQJx
 yX7ixUGe8B+h4TQzu9XHkPW756eguWRXFG/l4a7+mjULlzkzxuexDarS2rKbX/M65qvPN36oP
 DWF28K8TR9GMvLyaq1UkHGI4OjuU/ZmZTs/V2cxsj22bk96Dq0g8NnQuy7Lv6y0G6Wm5BFoFX
 pU+p83xrLlXh/FV6aUELQYbHfKUtrX+MGtMu/tMv0KKetjZD/9hgitpLEwL+cU30YM3Ax7/J1
 HE+tqtfqu5hFexNw8lVaKSp6RkRvgncb3mKHx6Xj8w==
X-Spam-Status: No, score=-97.7 required=5.0 tests=BAYES_00,
 GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE,
 RCVD_IN_MSPIKE_H2, SPF_FAIL, SPF_HELO_NONE,
 TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Corinna Vinschen <corinna-cygwin@cygwin.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On Apr  6 04:43, Fergus Daly via Cygwin wrote:
> I have a "hash bang" bash shell script i.e. first line
> #! /bin/sh
> or equivalently
> #! /bin/bash
> For various reasons I want this file to be identified as binary so its second line
> is the single character null \x00 showing up in some editors e.g. nano as
>  ^@
> This does not prevent the script from running to a successful conclusion.
> Or not until recently. Now the script fails with
> /home/user/bin/file.old.sh: cannot execute binary file
> Q1 - was bash recently updated? Would this explain the changed behaviour?

bash was recently updated from 4.4.12 to 5.2.15.

The behaviour is the same in bash on Linux.  Take this file with
a \0 in line 2:

  $ cat -v x.sh
  #! /bin/bash
  ^@
  echo foo
  $ bash --version | head -1
  GNU bash, version 5.2.15(1)-release (x86_64-redhat-linux-gnu)
  $ ./x.sh
  ./x.sh: ./x.sh: cannot execute binary file

While dash on Linux runs the script:

  $ sed -i -e 's/bash/dash/' x.sh
  $ ./x.sh
  foo

> Q2 - if so, is this newly introduced "glitch" known and presumably
> intended? Or an unintended consequence that will be retracted in a
> later update? 

Bash follows the POSIX standard:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html#tag_20_117_07
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403

So I don't expect this will change any time soon.

> Q3 - at 1/8 the size of bash and sh, I am not at all sure of the role and reach of dash.

Dash is a minimal shell with no bells and whistles.  It loads ands runs
slightly faster than bash.  If you only need bare minimum bourne shell
behaviour, it's a good choice for scripts.


Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
