bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shebang-less script execution not resetting some options


From: Greg Wooledge
Subject: Re: shebang-less script execution not resetting some options
Date: Tue, 1 Oct 2019 08:41:35 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]