Last active
August 29, 2015 13:59
-
-
Save kojiromike/10995204 to your computer and use it in GitHub Desktop.
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 | |
# You could use array indices with any version of bash: | |
declare -a processes | |
filenames=( dir/* ) | |
for filenum in "${!filenames[@]}"; do | |
filename=${filenames[filenum]} | |
run_step1 "$filename" > "${filename}.out" & | |
processes[filenum]=$! | |
done | |
for filenum in "${!filenames[@]}"; do | |
filename=${filenames[filenum]} | |
wait "${processes[filenum]}" && # Check the exit status | |
run_step2 "${filename}.out" > "${filename}.result" | |
done | |
# Or you could use associative arrays with bash 4: | |
declare -A processes | |
for f in dir/*; do | |
run_step1 "$f" > "${f}.out" & | |
processes[$f]=$! | |
done | |
for f in "${!processes[@]}"; do # The ! gets us the keys | |
wait "${processes[$f]}" && # Check the exit status | |
run_step2 "${f}.out" > "${f}.result" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment