bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

background process in command substitution


From: Hyunho Cho
Subject: background process in command substitution
Date: Wed, 7 Oct 2020 23:39:35 +0900

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

[Prev in Thread] Current Thread [Next in Thread]