Yeah, it is weird. A better (?) function illustrating the problem is

function q; echo $argv;sleep $argv;echo $argv;end
q 10s&; q 3s&;q 6s&
10s
10s
3s
3s
6s
6s
Job 3, “q 6s&” has ended
Job 2, “q 3s&” has ended
Job 1, “q 10s&” has ended

The sequence should be job 2,3,1, yet the function calls are completed
in sequence (with observed delays) 10s, 3s and 6s rather than yielding

10s
3s
6s
3s
6s
10s

Using ".. ;and ... ;and ... &" to join statements would still only
process the last command in background and not the block of commands -
yielding results similar to above.

Steven
--
On Fri, 20 Jul 2012 at 03:15pm, Philip Ganchev wrote:

> On Fri, Jul 20, 2012 at 10:51 AM, Steven Hum <sdot...@gmail.com> wrote:
> > I posted this in the github issues and don't mean to double post, but if
> > "...statement...&" is intended only to work for simple commands, e.g.
> >
> > sleep 10s&; sleep 3s&; sleep 6s&
> >
> > (silly example, I know!) then I can close the ticket as this may not be a 
> > bug
> > by design.
> >
> > What I found was, for functions, e.g.
> >
> > 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
> [...]
> 
> This is very surprising to me. I'm curious about the rationale here. I
> would expect the output:
> 
> 1
> 2
> 3
> 1
> Job 1, “q 1 &” has ended
> 2
> Job 2, “q 2 &” has ended
> 3
> Job 3, “q 3 &” has ended
> 
> > If there is a correct "fish" way of spawning background function 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 either (not 
> > surprisingly
> > given the above!)
> 
> command1; and command2; and command3
> 
> [...]


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to