Using a for loop, you can iterate through the output of a command like
In the example below, I've written a for loop along with the
ls command and placed it in a shell file named
#!/bin/sh COUNT=0; for FILENAME in `ls` do COUNT=$((COUNT+1)) echo "$COUNT $FILENAME" done
running this file lists the contents of the current working directory, along with the current iteration.
$ ./test.sh 1 Mustache 2 test.sh