4 ms·
What this does is two things: - It keeps the state separate from the main shell, including $PWD (so the `cd` doesn't affect the main execution "thread") - It
by faho 8y ago
What this does is two things:
- It keeps the state separate from the main shell, including $PWD (so the `cd` doesn't affect the main execution "thread")
- It executes some script in the background
Fish's backgrounding is currently limited to single external commands (not even functions). That's https://github.com/fish-shell/fish-shell/issues/238 https://github.com/fish-shell/fish-shell/issues/238.
It also doesn't have the capability to keep $PWD separate, though other variables can of course be declared locally. That's https://github.com/fish-shell/fish-shell/issues/1439 https://github.com/fish-shell/fish-shell/issues/1439.
The workaround is, if you actually need this, to run it inside `fish -c`. Which is essentially what this syntax is doing in the background anyway (it needs to fork off because `chdir` applies to the entire process).
(Disclosure: I'm a fish developer)
- SomeHacker44 8y agoForking off a subshell is very different, I would think, than forking and execing a new shell, both from a resource standpoint and an open file standpoint.
- faho 8y agoNot really from a usage perspective though, and resources often don't matter. If you're doing something like this in the background, then that usually means it takes a "long" time (or you'd just wait for it). So the overhead of starting an additional shell simply isn't important. Not that it's always irrelevant, but that's why the issues are still open.
- SomeHacker44 8y agoAgreed, resources often don't matter. But I do often do something like: ( cd somewhere ; do_something ) just so I can avoid having to do pushd somewhere ; do_something ; popd (or the equivalent).
- barrkel 8y agoDifference being that the fork is copy on write, so it can be quite a bit faster and need no initialization. Not to mention not needing to quote quotes and escape escapes.