help-bash
[Top][All Lists]
Advanced

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

Re: running in the background


From: Seth David Schoen
Subject: Re: running in the background
Date: Wed, 9 Dec 2020 10:35:15 -0800
User-agent: Mutt/1.9.4 (2018-02-28)

I fully agree with Greg Wooledge's thoughts about synchronization and
interprocess communication being a very complex subject.  However, the
bash "wait" command can deal with a subset of these complexities in a
way that might sometimes be helpful.  Just to give an example:


temp=$(mktemp)
command1 | command2 | etc > $temp &
# do some other stuff here
wait
variable=$(cat $temp)
rm $temp


This has its limitations and disadvantages, but it could be useful in
the context of the original question.

As Greg said, you can't use the variable until you set it, and you can't
set it until you know the output is available, which you can't know
until you confirm the original commands are completed.  The "wait"
builtin command will wait until the subprocess has finished, at which
point the redirected output will be available in the tempfile.

-- 
Seth David Schoen <schoen@loyalty.org>      |  Qué empresa fácil no pensar
     http://www.loyalty.org/~schoen/        |  en un tigre, reflexioné.
  8F08B027A5DB06ECF993B4660FD4F0CD2B11D2F9  |        -- Borges, "El Zahir"



reply via email to

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