Wednesday, April 9, 2008

iter.sh

My CSE303 instructor said it wasn't possible to iterate through a script's arguments through numbers, but I managed to get something working.

#!/bin/sh

for i in $(seq 1 $#); do
x="$(eval echo \$\{$i\})"
echo $x
done
% sh iter.sh 1 2 3 4 5 6
1
2
3
4
5
6
Unlike shift, you can have any subset of the arguments.

No comments: