Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15442

Re: shebang-less script execution not resetting some options

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: shebang-less script execution not resetting some options
Date Tue, 1 Oct 2019 08:41:35 -0400
Lines 32
Approved bug-bash@gnu.org
Message-ID <mailman.576.1569933727.2651.bug-bash@gnu.org> (permalink)
References <CAMu=BrpjDvF9Rz=JFaGoxV5AwjRoq=aC1htaybVz_kPFsDinbA@mail.gmail.com> <5D9334F8.3090503@tlinx.org> <20191001124135.GJ28751@eeg.ccf.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1569933728 10203 209.51.188.17 (1 Oct 2019 12:42:08 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
Mail-Followup-To bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <5D9334F8.3090503@tlinx.org>
User-Agent Mutt/1.10.1 (2018-07-13)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
X-Received-From 139.137.100.1
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <20191001124135.GJ28751@eeg.ccf.org>
X-Mailman-Original-References <CAMu=BrpjDvF9Rz=JFaGoxV5AwjRoq=aC1htaybVz_kPFsDinbA@mail.gmail.com> <5D9334F8.3090503@tlinx.org>
Xref csiph.com gnu.bash.bug:15442

Show key headers only | View raw


On Tue, Oct 01, 2019 at 04:14:00AM -0700, L A Walsh wrote:
> On 2019/09/30 14:39, Grisha Levit wrote:
> > A few of the recently-added shopt options aren't getting reset when
> > running a shebang-less script, this should fix it up:
> >   
> Suppose the shebang-less script is being run by an earlier version
> of bash.  Won't the new patch radically change the behavior of of
> such programs?

Bash executes an external program by forking, and then attempting to
exec the command it has been given.  If the kernel returns ENOEXEC,
bash reads 128 bytes from the file, sees if any of them are NUL, and
if not, it decides to execute the contents of the file itself.

Since bash has already forked, we're already in a subshell.  So bash
just cleans things up (it calls reset_parser() and initialize_subshell())
and then reads the commands from the file.

So, the version of bash that executes the shebang-less "script" is the
same as the version of bash that we began with.  There's no way it can
be an "earlier version".

> Does posix define the behavior of a child script with no interp-line?

I can't cite chapter and verse here, but basically every C program and
every shell handle it differently.

Bash allows a child of itself (a subshell) to read the commands.
GNU find -exec uses /bin/sh to run it.
zsh and csh both use /bin/sh to run it, I think.
systemd's ExecStart= refuses to run it (honors the ENOEXEC).  I think.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: shebang-less script execution not resetting some options Greg Wooledge <wooledg@eeg.ccf.org> - 2019-10-01 08:41 -0400

csiph-web