sh: Add test for obscure and ambiguous ${#?}.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sat, 16 Apr 2011 21:48:06 +0000 (11:48 -1000)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sat, 16 Apr 2011 21:55:53 +0000 (11:55 -1000)
Obtained-from: FreeBSD

tools/regression/bin/sh/expansion/length4.0 [new file with mode: 0644]

diff --git a/tools/regression/bin/sh/expansion/length4.0 b/tools/regression/bin/sh/expansion/length4.0
new file mode 100644 (file)
index 0000000..4f1fa3e
--- /dev/null
@@ -0,0 +1,11 @@
+# $FreeBSD: src/tools/regression/bin/sh/expansion/length4.0,v 1.1 2011/04/15 15:26:05 jilles Exp $
+
+# The construct ${#?} is ambiguous in POSIX.1-2008: it could be the length
+# of $? or it could be $# giving an error in the (impossible) case that it
+# is not set.
+# We use the former interpretation; it seems more useful.
+
+:
+[ "${#?}" = 1 ] || echo '${#?} wrong'
+(exit 42)
+[ "${#?}" = 2 ] || echo '${#?} wrong'