Skip to content

Instantly share code, notes, and snippets.

@kojiromike
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kojiromike/10995204 to your computer and use it in GitHub Desktop.
Save kojiromike/10995204 to your computer and use it in GitHub Desktop.
#!/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