Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions parallel-bash.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ _setup_arguments::parallel-bash() {
_process_arguments::parallel-bash() {
declare job=0 cmds=""

# function for running stored processes
# runs tasks from cmds variable and resets cmds plus job count to default
_execute::_run_processes::parallel-bash() {
job=0
# all hail the eval lord
eval "${cmds}" &
cmds=""
}

# a wrapper function
# takes 1 argument
_execute::_process_arguments::parallel-bash() {
Expand All @@ -69,12 +78,7 @@ _process_arguments::parallel-bash() {
# `;` is added to last to prevent stopping the execution because of a failed process
export "cmds+=${1:-:} ; "
# when job == no_of_jobs_final, then reset it and then again start appending from job 1
[[ ${job} -eq "${NO_OF_JOBS}" ]] && {
job=0
# all hail the eval lord
eval "${cmds}" &
cmds=""
}
[[ ${job} -eq "${NO_OF_JOBS}" ]] && _execute::_run_processes::parallel-bash
}

# iterate over both input arrays
Expand All @@ -93,6 +97,10 @@ _process_arguments::parallel-bash() {
;;
esac

# when total commands is not divisible by $NO_OF_JOBS
# some remain unprocessed in the end
[ -n "${cmds}" ] && _execute::_run_processes::parallel-bash

# this is probably pointless as the processes might be already completed before even reaching this point
# todo: fix this
declare status
Expand Down