Skip to content

Instantly share code, notes, and snippets.

@indraniel
Created August 20, 2015 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indraniel/403f4b81a1a55d31d837 to your computer and use it in GitHub Desktop.
Save indraniel/403f4b81a1a55d31d837 to your computer and use it in GitHub Desktop.
A C-style loop iteration in bash
#!/bin/bash
declare -a arr=("echo 'hi'" "echo 'hello'")
for (( i = 0; i < ${#arr[@]} ; i++ )); do
printf "\n**** Running: ${arr[$i]} *****\n\n"
# Run each command in array
eval "${arr[$i]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment