From 81f962f3df0d7194b7a52c6f83259727759094c4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 11 Aug 2017 02:05:21 +0200 Subject: hush: teach getopts to set/unset OPTARG Signed-off-by: Denys Vlasenko --- shell/hush_test/hush-getopts/getopt_optarg.right | 18 ++++++++++++++++++ shell/hush_test/hush-getopts/getopt_optarg.tests | 16 ++++++++++++++++ shell/hush_test/hush-getopts/getopt_positional.tests | 1 - 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 shell/hush_test/hush-getopts/getopt_optarg.right create mode 100755 shell/hush_test/hush-getopts/getopt_optarg.tests (limited to 'shell/hush_test/hush-getopts') diff --git a/shell/hush_test/hush-getopts/getopt_optarg.right b/shell/hush_test/hush-getopts/getopt_optarg.right new file mode 100644 index 000000000..9dbd8460e --- /dev/null +++ b/shell/hush_test/hush-getopts/getopt_optarg.right @@ -0,0 +1,18 @@ +*** no OPTIND, optstring:'w:et' args:-q -w e -r -t -y +./getopt_optarg.tests: invalid option -- q +var:'?' OPTIND:2 OPTARG:'' +var:'w' OPTIND:4 OPTARG:'e' +./getopt_optarg.tests: invalid option -- r +var:'?' OPTIND:5 OPTARG:'' +var:'t' OPTIND:6 OPTARG:'' +./getopt_optarg.tests: invalid option -- y +var:'?' OPTIND:7 OPTARG:'' +exited: var:'?' OPTIND:7 OPTARG:'' +*** OPTIND=0, optstring:'w:et' args:-w 1 -w2 -w -e -e -t -t +var:'w' OPTIND:3 OPTARG:'1' +var:'w' OPTIND:4 OPTARG:'2' +var:'w' OPTIND:6 OPTARG:'-e' +var:'e' OPTIND:7 OPTARG:'' +var:'t' OPTIND:8 OPTARG:'' +var:'t' OPTIND:9 OPTARG:'' +exited: var:'?' OPTIND:9 OPTARG:'' diff --git a/shell/hush_test/hush-getopts/getopt_optarg.tests b/shell/hush_test/hush-getopts/getopt_optarg.tests new file mode 100755 index 000000000..b346284f0 --- /dev/null +++ b/shell/hush_test/hush-getopts/getopt_optarg.tests @@ -0,0 +1,16 @@ +set -- -q -w e -r -t -y +echo "*** no OPTIND, optstring:'w:et' args:$*" +var=QWERTY +OPTARG=ASDFGH +while getopts "w:et" var; do + echo "var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" +done +echo "exited: var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" + +set -- -w 1 -w2 -w -e -e -t -t +echo "*** OPTIND=0, optstring:'w:et' args:$*" +OPTIND=0 +while getopts "w:et" var; do + echo "var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" +done +echo "exited: var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" diff --git a/shell/hush_test/hush-getopts/getopt_positional.tests b/shell/hush_test/hush-getopts/getopt_positional.tests index a5404a2a0..ddf063363 100755 --- a/shell/hush_test/hush-getopts/getopt_positional.tests +++ b/shell/hush_test/hush-getopts/getopt_positional.tests @@ -4,5 +4,4 @@ var=QWERTY while getopts "we" var; do echo "var:'$var' OPTIND:$OPTIND" done -# unfortunately, "rc:0" is shown since while's overall exitcode is "success" echo "exited: var:'$var' OPTIND:$OPTIND" -- cgit v1.2.3