Putting a colon at the beginning of optstring to silence errors doesn't mean that the colon is a valid option. Before this patch, dash treated -: as a valid option if the optstring started with a colon. This patch fixes that problem. Test: getopts :a opt -: echo $opt$OPTARG Correct output - ?: Invalid output - : --- src/options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options.c b/src/options.c index 2d4bd3b..8593710 100644 --- a/src/options.c +++ b/src/options.c @@ -465,7 +465,7 @@ atend: } c = *p++; - for (q = optstr; *q != c; ) { + for (q = optstr[0] == ':' ? optstr + 1 : optstr; *q != c; ) { if (*q == '\0') { if (optstr[0] == ':') { s[0] = c; -- 2.39.1