getopts does not support multiple arguments to an option. A comma-separated list of values would be a single argument which you could then parse into individual values in the script.
Code:
./solar -s <string to be searched> -f <file1>,<file2>,<file3>
If the file names may contain whitespace characters then they would have to be quoted on the command line and parsed with IFS set to ",". Some error trapping techniques are also illustrated below
Code:
./solar -f 'my file,my other file'
while getopts f:s: opt 2>/dev/null
do
case $opt in
s)
search_string="$OPTARG"
;;
f )
IFS=',' files=($OPTARG)
;;
* )
<show short help message>
\exit 1
esac
done
# Test for extra arguments
# ~~~~~~~~~~~~~~~~~~~~~~~~
shift $(( $OPTIND-1 ))
if [[ $* != '' ]]; then
<show short help message>
\exit 1
fi
# Test for mandatory options not set
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [[ "$search_string" == '' -o "$files" == '' ]]; then
<show short help message>
\exit 1
fi
EDIT:
Code:
IFS=',' files=($OPTARG)
is dangerous; it leaves $IFS set to ",". See
this post for an explanation.