input file names to a script

What is a more efficient way to read files into a script? I don't want to hard code the file names like below:

for file in file1 \
             file2

do
...
done

I want to execute the script with a variable number for files for input like below:

./scriptname file1 file2 file3 ... and so on

How would I code that?

thanks.

for file in $@

You might want to use double-quotes around $@, otherwise any file names with embedded spaces will be split into two in your for loop:

for file in "$@"

Most Unix file-names do not use embedded spaces, but its always good to have your script ready to handle them. :slight_smile:

good catch - thanks!