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


Groups > gnu.bash.bug > #16515

Re: ‘command … &’ creates subshell

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Robert Elz <kre@munnari.OZ.AU>
Newsgroups gnu.bash.bug
Subject Re: ‘command … &’ creates subshell
Date Thu, 02 Jul 2020 00:46:33 +0700
Lines 62
Approved bug-bash@gnu.org
Message-ID <mailman.781.1593625634.2574.bug-bash@gnu.org> (permalink)
References <pn9ffe39.dag@gnui.org> <tuysgrgt.dag@gnui.org> <pn9hipci.dag@gnui.org> <ac4a98bd-32f4-5c55-3b8f-1306e9758f54@case.edu> <7dvoi92p.dag@gnui.org> <09ea84b2-4fb1-6b05-7c0b-fe6b2ab00c6f@archlinux.org> <2643.1593599092@jinx.noi.kre.to> <14637.1593625593@jinx.noi.kre.to>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1593625635 11078 209.51.188.17 (1 Jul 2020 17:47:15 GMT)
X-Complaints-To action@cs.stanford.edu
Cc Eli Schwartz <eschwartz@archlinux.org>, bug-bash@gnu.org
To Dmitry Alexandrov <dag@gnui.org>
Envelope-to bug-bash@gnu.org
In-Reply-To <pn9ffe39.dag@gnui.org>
X-Host-Lookup-Failed Reverse DNS lookup failed for 2001:3c8:9009:181::2 (failed)
Received-SPF permerror client-ip=2001:3c8:9009:181::2; envelope-from=kre@munnari.OZ.AU; helo=munnari.OZ.AU
X-detected-operating-system by eggs.gnu.org: No matching host in p0f cache. That's all we know.
X-Spam_score_int -10
X-Spam_score -1.1
X-Spam_bar -
X-Spam_report (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, T_SPF_HELO_PERMERROR=0.01, T_SPF_PERMERROR=0.01 autolearn=_AUTOLEARN
X-Spam_action no action
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 <14637.1593625593@jinx.noi.kre.to>
X-Mailman-Original-References <pn9ffe39.dag@gnui.org> <tuysgrgt.dag@gnui.org> <pn9hipci.dag@gnui.org> <ac4a98bd-32f4-5c55-3b8f-1306e9758f54@case.edu> <7dvoi92p.dag@gnui.org> <09ea84b2-4fb1-6b05-7c0b-fe6b2ab00c6f@archlinux.org> <2643.1593599092@jinx.noi.kre.to>
Xref csiph.com gnu.bash.bug:16515

Show key headers only | View raw


    Date:        Wed, 01 Jul 2020 18:29:46 +0300
    From:        Dmitry Alexandrov <dag@gnui.org>
    Message-ID:  <pn9ffe39.dag@gnui.org>

  | Well, I am not sure whether it's guaranteed, but the "exec"
  | as above does execute an external command in GNU Bash.

Yes, I know, but the way exec works in bash is broken (well, non-standard,
not POSIX compliant).

POSIX says:

	If command is specified, exec shall not return to the shell;

but in bash...

 bash
jinx$ echo $$
23361
jinx$ exec :
bash: exec: :: not found
jinx$ echo $$
23361
jinx$ exit
exit

"command was specified" yet exec returned to the shell.   That should
never happen (that it was unable to find the ':' builtin command to
execute is another problem - but that one is shared by several shells).

Turning on posix mode makes no difference:

bash -o posix
jinx$ echo $$
18742
jinx$ exec :
bash: exec: :: not found
jinx$ echo $$
18742
jinx$ exit
exit

These use 5.0.17(1)-release bash.

What is required of exec (with a "command" arg) is that the current
shell is replaced by the command, and when that exits, the process
that used to be the shell exits.

When not interactive bash seems to do this properly, but not when 
interactive.   The spec makes no variation for that case,

There's nothing in the spec that limits what kind of command can be
exec'd (except to parse, it has to be a simple command, nothing else
fits into the grammar) though many shells treat the exec builtin as
simply a shorthand for a call to one of the exec*() system calls,
and consequently only work properly if there's a command in the filesystem
to run.

kre


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


Thread

Re: ‘command … &’ creates subshell Robert Elz <kre@munnari.OZ.AU> - 2020-07-02 00:46 +0700

csiph-web