From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lucy.dinwoodie.org (lucy.dinwoodie.org [IPv6:2001:8b0:de15:20ad:6beb:fd8f:c6fd:d1ac]) by sourceware.org (Postfix) with ESMTPS id 914473858D28 for ; Thu, 6 Apr 2023 17:19:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 914473858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dinwoodie.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dinwoodie.org Received: from adam by lucy.dinwoodie.org with local (Exim 4.96) (envelope-from ) id 1pkTGF-000phi-0l; Thu, 06 Apr 2023 18:18:59 +0100 Date: Thu, 6 Apr 2023 18:18:59 +0100 From: Adam Dinwoodie To: Fergus Daly Cc: "'cygwin@cygwin.com'" Subject: Re: bash shell script: recently running, now failing Message-ID: <20230406171859.ud6jsdxgwtulu6cg@lucy.dinwoodie.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,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 List-Id: On Thu, Apr 06, 2023 at 04:43:51AM +0000, 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? > Q2 - if so, is this newly introduced "glitch" known and presumably intended? Or > an unintended consequence that will be retracted in a later update? > I then altered the first line to > #! /bin/dash > whilst retaining the null character at line 2 and subsequent content also unaltered.. > The altered script file.new.sh runs as previously to a successful conclusion. > Q3 - at 1/8 the size of bash and sh, I am not at all sure of the role and reach of dash. > Should the edit (dash replacing bash/sh) be incorporated elsewhere or would this be a > bad idea (and retained only locally in what is indeed an eccentric and one-off context)? Dash is smaller and much less feature-rich than Bash. Whether Dash is a suitable replacement for Bash depends on how much (if at all) you're relying on Bash-specific functions. For very simple scripts, the only difference is likely that Dash will be very slightly faster, but working out whether your script is using any "Bashisms" isn't always a trivial job. (I have previously been involved work in migrating scripts between Ksh and Bash, which is a similar-but-different problem, and there were *a lot* of surprises in how the two differed.) Depending on why you want the file to be identified as a binary, and how that identification is being done, you could move your null byte later in the file. In particular, a pattern I've seen several times in Bash is to have a normal Bash script, finishing with an explicit `exit`, followed by an actual binary blob; this can be used to create things like self-extracting bundles, where the binary blob is a tarball and the script at the top of the file has the instructions for extracting the tarball.