fish-shell / fish-shell/fish-shell
"... &" background statement cannot work with functions?
- 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
Assessment
This issue has not been assessed yet.