1

I have a bash script.

f1 () { for ((i=1; i<6; i++)) do a=$(echo -e "\033[41m ") echo -n " $a"; echo -en "\033[0m"; sleep 1; echo -en "\b"; echo -n ' ' done } f2 () { a=$(echo -e "\033[41m \033[0m") echo -en "\033[5;50H$a" for ((i=1; i<6; i++)) do echo -en "\b" echo -en ' ' echo -en "\b\b" echo -n "$a" sleep 1 echo -en "\033[0m" done } f1 f2 

f1 shifts the object to the right; f2 shifts another object to the left;

what can I do to execute both functions at the same time, so that I see both objects move at the same time?

#this wont work f1 & f2 & 
2
  • I installed parallel,though am getting error message after running the code in the answer. Commented Apr 9, 2014 at 10:11
  • the error message is :parallel: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit. Commented Apr 9, 2014 at 10:18

1 Answer 1

1

Run them in background with parallel:

 #export functions so parallel can see them export -f f1 export -f f2 #run both functions parallel f1 f2 
Sign up to request clarification or add additional context in comments.

6 Comments

also, wait is useful as well. Since it, well, waits for all subproceses to finish before continuing. To run something truly parallel, google gnu parallel
Oh, true, I didn't understand the last line, you need to use parallel for this.
@computer10 this version does the job.
i need to install parallel for ubuntu 64 bit.can you give me immediate instructions. apt-get ... or link.
sudo apt-get install parallel
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.