Last active
May 21, 2024 21:58
-
-
Save manboubird/4a2fa1f8b9fde66b8442f1f765d5e9fc to your computer and use it in GitHub Desktop.
GNU parallel bash fuction execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# GNU Parallel and Bash functions: How to run the simple example from the manual - Stack Overflow | |
# http://stackoverflow.com/questions/23814360/gnu-parallel-and-bash-functions-how-to-run-the-simple-example-from-the-manual | |
# | |
SCRIPT_DIR="$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)" | |
WORKSPACE=${WORKSPACE:-$(pwd)} | |
log() { echo "[$(date +"%F %T")] $@"; } | |
doit () { | |
echo prams = $@ | |
} | |
export -f doit | |
main() { | |
log "executing parameters combination in prallel" | |
params1=(1 2 3 4 5) | |
params2=(a b c d e) | |
parallel --dry-run --results ${WORKSPACE}/gnu-parallel-results --joblog ${WORKSPACE}/gnu-parallel-job.log -j2 --tag --line-buffer doit {1} {2} ::: ${params1[@]} ::: ${params2[@]} | |
log "executing parameters combination in prallel" | |
INPUT_FILE=${WORKSPACE}/input.tsv | |
cat <<EOF > ${INPUT_FILE} | |
1 a | |
2 b | |
3 c | |
4 d | |
5 e | |
EOF | |
parallel --results ${WORKSPACE}/gnu-parallel-results --joblog ${WORKSPACE}/gnu-parallel-job.log -a ${INPUT_FILE} --colsep '\t' -j2 --tag --line-buffer doit {1} {2} | |
} | |
main | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment