osx - Run background processes on a single queue -


on os x, i'm trying run "say" commands background processes on own queue, separate main process echo statements. example:

echo "hello" "hello" &       # first in queue  echo "and"          # should printed after first echo,                     # without waiting command finish. "and" &         # begins first command finished  echo "goodbye"      # should printed out without waiting command "goodbye" &     # begins second command finished 

the current problem commands ran asynchronously , said @ same time. here current attempt @ solution:

export v_queue=() function q_push { v_queue=("${v_queue[@]}" $1); } function q_shift { v_queue=(${v_queue[@]:1}); }  function speakbg {     while (( ${#v_queue[*]} > 0 ))             wait ${v_queue[0]}         q_shift     done     "$*" }  function speak {     speakbg "$*" &    # desired result achieved removing '&', echos should printed immediately!     q_push $! }   echo "hello" speak "hello" echo "and" speak "and" echo "goodbye" speak "goodbye" 


Comments