# This test can fail with libc with buggy getopt() implementation.
# If getopt() wants to parse multi-option args (-abc),
-# it needs to remember a position withit current arg.
+# it needs to remember a position within current arg.
#
# If this position is kept as a POINTER, not an offset,
# and if argv[] ADDRESSES (not contents!) change, it blows up.
VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
VAR333=NEWVAL; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
-# Sligntly different attempts to force reallocations
+# Slightly different attempts to force reallocations
echo
echo "*** optstring:'ac' args:-a -b -c -d e"
+(
+
set -- -q -w e -r -t -y
echo "*** no OPTIND, optstring:'w:et' args:$*"
var=QWERTY
OPTARG=ASDFGH
done
echo "exited: var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
+
+) 2>&1 \
+| sed -e 's/ unrecognized option: / invalid option -- /' \
+ -e 's/ illegal option -- / invalid option -- /' \
+(
+
set -- -q -w -e r -t -y
echo "*** no OPTIND, optstring:'we' args:$*"
var=QWERTY
echo "var:'$var' OPTIND:$OPTIND"
done
echo "exited: var:'$var' OPTIND:$OPTIND"
+
+) 2>&1 \
+| sed -e 's/ unrecognized option: / invalid option -- /' \
+ -e 's/ illegal option -- / invalid option -- /' \
# and OPTARG shall be set to the option character found.
# """
+(
+
echo "*** optstring:':ac' args:-a -b -c"
getopts ":ac" var -a -b -c; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
getopts ":ac" var -a -b -c; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
# Nevertheless, let's verify that calling it yet another time doesn't do
# anything weird:
getopts ":ac" var -a -b -c; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
+
+) 2>&1 \
+| sed -e 's/ unrecognized option: / invalid option -- /' \
+ -e 's/ illegal option -- / invalid option -- /' \
# We check that loop does not stop on unknown option (sets "?"),
# stops on _first_ non-option argument.
+(
+
echo "*** no OPTIND, optstring:'ab' args:-a -b c"
var=QWERTY
while getopts "ab" var -a -b c; do
echo "var:'$var' OPTIND:$OPTIND"
done
echo "exited: rc:$? var:'$var' OPTIND:$OPTIND"
+
+) 2>&1 \
+| sed -e 's/ unrecognized option: / invalid option -- /' \
+ -e 's/ illegal option -- / invalid option -- /' \
# This test can fail with libc with buggy getopt() implementation.
# If getopt() wants to parse multi-option args (-abc),
-# it needs to remember a position withit current arg.
+# it needs to remember a position within current arg.
#
# If this position is kept as a POINTER, not an offset,
# and if argv[] ADDRESSES (not contents!) change, it blows up.
+(
+
echo "*** optstring:'ac' args:-a -b -c -d e"
getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
VAR333=NEWVAL; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
-# Sligntly different attempts to force reallocations
+# Slightly different attempts to force reallocations
echo
echo "*** optstring:'ac' args:-a -b -c -d e"
export VAR333; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
# All copies of code above should generate identical output
+
+) 2>&1 \
+| sed -e 's/ unrecognized option: / invalid option -- /' \
+ -e 's/ illegal option -- / invalid option -- /' \