In bash script, is it possible to assign a value which will be calculated
by a background process to a variable?
if I have a script like this:
#!/bin/bash
echo `script2.sh` > temp.txt &
(wait for long enough time)
a=`cat temp.txt`
echo $a
a's value will be successfully changed by script2.sh. However, if I do this:
#!/bin/bash
a=`script2.sh` &
(wait for long enough time)
echo $a
a's value would not be changed by script2.sh. The reason why I want to do
this is becasue:(1)I do not want the main process to be blocked by the
script2.sh(during waiting,I can do something else) (2)My main program will
do a lot of such stuff, so doing a lot of file IOs will give me a big
overhead and it's better to directly assign the value to a variable in
memory. I have found the file IO in bash script is really very slow. In my
program,doing 400 such IOs will take about 10 seconds (when the computer
is busy though)! Any suggestion?
No comments:
Post a Comment