shift $((OPTIND-1)) (nota OPTIND é maiúscula) é normalmente encontrado imediatamente após um loop getopts while . $OPTIND é o número de opções encontradas por getopts .
Como pauljohn32 menciona nos comentários, estritamente falando, OPTIND fornece a posição do argumento de linha de comando próximo .
Do GNU Manual de Referência do Bash :
getopts optstring name [args]
getoptsis used by shell scripts to parse positional parameters.optstringcontains the option characters to be recognized; if a character is followed by a colon, the option is expected to have an argument, which should be separated from it by whitespace. The colon (‘:’) and question mark (‘?’) may not be used as option characters. Each time it is invoked,getoptsplaces the next option in the shell variable name, initializingnameif it does not exist, and the index of the next argument to be processed into the variableOPTIND.OPTINDis initialized to 1 each time the shell or a shell script is invoked. When an option requires an argument, getopts places that argument into the variableOPTARG. The shell does not resetOPTINDautomatically; it must be manually reset between multiple calls togetoptswithin the same shell invocation if a new set of parameters is to be used.When the end of options is encountered,
getoptsexits with a return value greater than zero.OPTINDis set to the index of the first non-option argument, and name is set to ‘?’.
getoptsnormally parses the positional parameters, but if more arguments are given inargs,getoptsparses those instead.
shift n
remove n strings da lista de parâmetros posicionais. Assim, shift $((OPTIND-1)) remove todas as opções que foram analisadas por getopts da lista de parâmetros e, após esse ponto, $1 se referirá ao primeiro argumento de não-opção passado para o script.
Atualizar
Como mikeserv menciona o comentário, shift $((OPTIND-1)) pode não ser seguro. Para evitar a divisão indesejada de palavras, etc., as expansões de parâmetro all devem ter aspas duplas. Então, a forma segura para o comando é
shift "$((OPTIND-1))"