This repository has been archived by the owner on Jun 1, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified running a command on multiple datasets
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Execute parallel commands per folder, collecting the output on stout. | ||
# | ||
# USAGE | ||
# "$0" <folder(s)> -- <command(s)> | ||
# "$0" "folder0" "folder1" "folderN" -- mycommand --option --whatever '{}' | ||
# "$0" "folder0" "folder1" "folderN" -- echo '"\"This data from the pipe\""' '|' jq --arg folder '{}' --arg pwd '"$PWD"' "'{ folder: \$path, pwd: \$pwd, pipe: . }'" | ||
# | ||
# Separate folder(s) and command(s) with "--". | ||
# Use '{}' in the command to get the folder as input. | ||
# The entire command doesn't have to be a string - everything after '--' will be executed. | ||
# Quote strings used in the command twice; '"string with spaces"'. | ||
# Separate shell commands like semicolon, ampersands and pipe need to be quoted. | ||
|
||
folders=() | ||
|
||
while [[ "$1" != "--" ]]; do | ||
folders+=("$1") | ||
|
||
shift | ||
done | ||
|
||
shift | ||
|
||
command="$@" | ||
|
||
parallel --group -N 1 cd "--" "{}" "&&" "$command" ::: "${folders[@]}" |