fish-shell / fish-shell/fish-shell

"... &" background statement cannot work with functions?

Open
#238 30 comments 55 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
34.2k
Forks
2.4k
Avg merge
2d 8h
Merged PRs (30d)
13

Description

Does the "... &" statement only work with simple commands and not functions? For example, if I have defined

```
function q; echo $argv; sleep 10s; echo $argv; end
```

and execute

```
q 1 &; q 2 &; q 3 &
```

the output is

```
1
1
2
2
3
3
Job 3, “q 3 &” has ended
Job 2, “q 2 &” has ended
Job 1, “q 1 &” has ended
```

with the observed performance (delay) indicating that each successive "q" command is not executed until the previous command is completed. I use in POSIX sh "(sleep [some delay] && [command]) &" quite commonly in startup scripts e.g. for window managers to allow for the initialization requirements of certain apps.

If there is a correct "fish" way of spawning multiple background processes, my second question is: is there a way to spawn a block of commands in background similar to POSIX "(command1 && command2 && command3...) &". I tried "begin; ...statements...; end &" but fish does not like that!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.