No -silencioso, getopts
imprime un mensaje de error:
$ bash -c 'getopts a opt' getopts_test -b
getopts_test: illegal option -- b
Silencio, getopts
no lo imprime solo:
$ bash -c 'getopts :a opt' getopts_test -b
$
Entonces, con los dos puntos para el modo silencioso, podemos imprimir nuestro propio error en el script tal como nos gusta, en lugar del mensaje fijo:
#!/bin/bash
while getopts :a opt; do
[[ $opt = "?" ]] && echo "Invalid option character '$OPTARG'" >&2;
done