<p>Can you use the bash "getopts" function twice in the same script?</p>

<p>I have a set of options that would mean different things depending on the value of a specific option.  Since I can't guarantee that getopts will evaluate that specific option first, I would like to run getopts one time, using only that specific option, then run it a second time using the other options.</p>

Yes, just reset OPTIND afterwards.
```
```
#!/bin/bash

set -- -1
while getopts 1 opt; do
    case "${opt}" in
        1) echo "Worked!";;
        *) exit 1;
    esac
done

OPTIND=1
set -- -2
while getopts 2 opt; do
    case "${opt}" in
        2) echo "Worked!";;
        *) exit 1;
    esac
done
```
```