1) As catkin asked above, please use
[code][/code] tags around your code, to preserve formatting and to improve readability.
2) As I said, you have to reverse the process. Save the first two parameters to variables first, then shift
2 to remove them from the command list, then use getopts on the rest.
Code:
filename="$1"
port="$2"
shift 2
while getopts ...
Be aware that this means
filename and
port must always come first, and in that order, since they are processed first in the code and then their parameters are discarded.
Again, this just reverses the traditional pattern, where the getopts options are processed first, and discarded, so that whatever is left can be used in other ways.
Look at the link I gave you and
carefully read how getopts works. Look up what shift does too if necessary (hint, there's a link to "handling positional parameters" on that page that explains it, along with other useful info related to this topic).
Or you could just give the "mandatory" arguments their own getopts flags too, then you wouldn't have to worry about the order they come in at all.