You're correct when you say you're "not using stdin correctly". In fact, from the script snippet you provided, your script assumes you're getting the files as arguments on the command line ... you're not using stdin at all!
In the top right corner of the Run Shell Script action, below the X is a drop down box with 2 options: 'Pass input: to stdin' and 'Pass intput: as arguments'. These options dictate how the selected files are passed to your script action. If the option 'as arguments' is selected, your script should use the following template
for f in "$@"; do
# so stuff here
done
This template is provided by the action itself when 'as arguments' is selected.
On the other hand, if the 'to stdin' option is selected, then you script should use this tamplate:
while read fname; do # read each line - assumes one file name per line
# do clever stuff with the filename
echo $fname # to illustrate we'll simply copy the filename to stdout
done
(In the event you don't know bash scripting, everything after the # on a line is a comment)
Note that the template provided by the script action is the simple, single command
cat
Not very helpful in my opinion.
Note that until you actually enter text into script area, changing between 'to stdin' and 'as arguments' will change the contents of the script box (I assume this is a hint to what your script should look like) but once you enter something, the switching no longer happens.