When you put the '*' on the command line the shell will do the expansion before calling the script. When the script is called it may have more then one parameter. Take this example:
Code:
#!/bin/sh
# Script: test.sh
echo $1
echo $2
echo $3
Code:
# touch test1.txt
# touch test2.txt
# touch test3.txt
# ./test.sh test*.txt
test1.txt
test2.txt
test3.txt
The shell will find all the matches for test*.txt and substitute it for original text.
Code:
./test.sh test*.txt
./test.sh test1.txt test2.txt test3.txt
So this script should work for any number of parameters:
Code:
#!/bin/sh
for i in $@; do
echo $i
done