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


Groups > gnu.bash.bug > #16505

Re: ‘command … &’ creates subshell

From Robert Elz <kre@munnari.OZ.AU>
Newsgroups gnu.bash.bug
Subject Re: ‘command … &’ creates subshell
Date 2020-07-01 17:24 +0700
Message-ID <mailman.739.1593599160.2574.bug-bash@gnu.org> (permalink)
References (1 earlier) <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>

Show all headers | View raw


    Date:        Wed, 01 Jul 2020 00:43:14 +0300
    From:        Dmitry Alexandrov <dag@gnui.org>
    Message-ID:  <tuysgrgt.dag@gnui.org>

  | > If you need to ensure a disk executable is used,
  | Of course.  Why "command" otherwise?

That doesn't actually work, "command" can run built-ins, there is
actually no method (not even via use of "env") which guarantees
execution of an executable from an external file, other than by
using the complete path name (containing at least one '/') of the
desired file.

command avoids executing functions.   That's its purpose (so you
can write

	cd() {
		test "$1" = "-b" && set -- whatever
		command cd "$@"
	}

(probably not quite that) without getting recursive "cd' invocation.

It also changes the rules for what happens with errors encountered
with special builtins (but unless in posix mode, bash tends to ignore
those anyway).

When given no options (just args) or with just -p (and args), there's no
reason at all for "command" to ever invoke a subshell for itself, all it
does is alter the search strategy for the command name that follows.

I'd actually call bash's behaviour a bug, and if not strictly that,
then certainly "extraordinarily non-intuitive" - rather than just an
"untaken (yet) opportunity for optimisation".

kre

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


Thread

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

csiph-web