There are cases that need not wait until background process finish

----------------------------------------------------------------------

In this case, zsh and bash wait 3 seconds to finish the assignment operation.
because sleep command's STDOUT is the pipe of command substitution.

< zsh >

$ AA=$( sleep 3 & date )        # wait 3 seconds to finish

< bash >

$ AA=$( sleep 3 & date )        # same as zsh

----------------------------------------------------------------------------

In this case, sleep command's STDOUT is redirected to FD 3
so there is no needs to wait 3 seconds
zsh return immediately with the value of background process PID
but bash still waits 3 seconds to finish the assignment operation.

< zsh >

$ exec 3>&1
$ PID=$(
    date > >( sleep 3 >&3 ) & echo $!
)


< bash >

$ exec 3>&1
$ PID=$(
    date > >( sleep 3 >&3 ) & echo $!
)

Reply via email to