summaryrefslogtreecommitdiffstats
path: root/bin/sh/tests/builtins
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-05-10 17:42:21 +0000
committerjilles <jilles@FreeBSD.org>2014-05-10 17:42:21 +0000
commit56ecdb9ab8305061131a36935ec6bbaf949439ba (patch)
tree3571eb5ebfa9d5f1c5dafb85dcb4962d6f5dc846 /bin/sh/tests/builtins
parent7798d7f7f405786a5591626ffc1c59f60134d434 (diff)
downloadFreeBSD-src-56ecdb9ab8305061131a36935ec6bbaf949439ba.zip
FreeBSD-src-56ecdb9ab8305061131a36935ec6bbaf949439ba.tar.gz
sh: Don't discard getopts state on unknown option or missing argument.
When getopts finds an invalid option or a missing option-argument, it should not reset its state and should set OPTIND as normal. This is an old ash bug that was fixed long ago in dash. Our behaviour now matches most other shells.
Diffstat (limited to 'bin/sh/tests/builtins')
-rw-r--r--bin/sh/tests/builtins/getopts6.07
-rw-r--r--bin/sh/tests/builtins/getopts7.06
2 files changed, 13 insertions, 0 deletions
diff --git a/bin/sh/tests/builtins/getopts6.0 b/bin/sh/tests/builtins/getopts6.0
new file mode 100644
index 0000000..1d3c39b
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts6.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+set -- -x -y
+getopts :x var || echo "First getopts bad: $?"
+getopts :x var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 3 ]
diff --git a/bin/sh/tests/builtins/getopts7.0 b/bin/sh/tests/builtins/getopts7.0
new file mode 100644
index 0000000..3745555
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts7.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -- -x
+getopts :x: var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 2 ]
OpenPOWER on IntegriCloud