Skip to main content
1 of 2
Hauke Laging
  • 94.6k
  • 21
  • 132
  • 185

You need eval:

for ((i=0; i < $1; ++i)); do 
    echo "iterator=$i"; 
    # for debugging
    echo eval "$3"
    eval "$3"
done

Of course, you must pay attention to the right quoting in the command string. Your example ls *$(($2 + $i ))*.gnu | wc -l isn't dangerous in this sense, though.

Hauke Laging
  • 94.6k
  • 21
  • 132
  • 185