#!/bin/sh # # This script prints out it's command line arguments, # one per line (using a foreach loop) and includes line numbers # (shows how to use a variable as a counter) echo I got $# arguments, and here they are: # First we show that this doesn't work - the bourne shell # doesn't understand arithmetic operators: linenum=0 echo echo The wrong way first: for i in $@; do echo param $linenum is $i linenum=$linenum+1 done echo echo "This is the right way:" # This on works - it uses the expr command linenum=0 for i in $@; do echo param $linenum is $i linenum=`expr $linenum + 1` done