Skip to content

Commit b07e2ac

Browse files
authored
Ensures the handling of OPTARG is consistent with Bash’s getopts (#30)
Implements the fix from PR #16 and updates the tests to use `declare` for validating OPTARG.
1 parent 449d7d1 commit b07e2ac

22 files changed

+74
-73
lines changed

lib/getopts_long.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ getopts_long() {
4646
fi
4747
elif [[ " ${optspec_long} " == *" ${!optvar} "* ]]; then
4848
unset OPTARG
49+
declare -g OPTARG
4950
else
5051
# Invalid option
5152
if [[ "${optspec_short:0:1}" == ':' ]]; then

test/bats/github_15a.bats

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ load ../test_helper
3737
'--toggle-- --toggle user_arg' \
3838
'1{/^toggle triggered/d}' \
3939
'/^INVALID OPTION/d'
40-
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset'
41-
expect "${bash_getopts[2]}" == 'INVALID OPTION -- OPTARG=-'
42-
expect "${bash_getopts[3]}" == 'INVALID OPTION -- OPTARG=-'
43-
expect "${bash_getopts[4]}" == 'toggle triggered -- OPTARG is unset'
44-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=toggle--'
45-
expect "${getopts_long[2]}" == 'toggle triggered -- OPTARG is unset'
40+
expect "${bash_getopts[2]}" == 'INVALID OPTION -- OPTARG="-"'
41+
expect "${bash_getopts[3]}" == 'INVALID OPTION -- OPTARG="-"'
42+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="toggle--"'
43+
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG'
44+
expect "${bash_getopts[4]}" == 'toggle triggered -- OPTARG'
45+
expect "${getopts_long[2]}" == 'toggle triggered -- OPTARG'
4646
}
4747
@test "${FEATURE}: long toggle, verbose" {
4848
compare '-t-- -t user_arg' \
@@ -52,12 +52,12 @@ load ../test_helper
5252
'5{/^INVALID OPTION or MISSING ARGUMENT/d}' \
5353
's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' \
5454
's/(illegal option --) (-|toggle--)/\1 TOGGLE-NORMALISED/'
55-
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset'
55+
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG'
5656
expect "${bash_getopts[2]}" =~ 'getopts-verbose: illegal option -- -$'
5757
expect "${bash_getopts[4]}" =~ 'getopts-verbose: illegal option -- -$'
58-
expect "${bash_getopts[6]}" == 'toggle triggered -- OPTARG is unset'
58+
expect "${bash_getopts[6]}" == 'toggle triggered -- OPTARG'
5959
expect "${getopts_long[1]}" =~ 'getopts_long-verbose: illegal option -- toggle--$'
60-
expect "${getopts_long[3]}" == 'toggle triggered -- OPTARG is unset'
60+
expect "${getopts_long[3]}" == 'toggle triggered -- OPTARG'
6161
}
6262

6363
# Both implementations should see:
@@ -82,14 +82,14 @@ load ../test_helper
8282
compare '-o-- -t user_arg' \
8383
'--option-- --toggle user_arg' \
8484
'1{/(option supplied|INVALID OPTION)/d}'
85-
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
86-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=option--'
85+
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
86+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="option--"'
8787
}
8888
@test "${FEATURE}: long option, verbose" {
8989
compare '-o-- -t user_arg' \
9090
'--option-- --toggle user_arg' \
9191
'1{/(option supplied|illegal option)/d}' \
9292
'2{/^INVALID OPTION or MISSING ARGUMENT/d}'
93-
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
93+
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
9494
expect "${getopts_long[1]}" =~ "getopts_long-verbose: illegal option -- option--$"
9595
}

test/bats/github_15b.bats

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-shortspec_with_dash'
4040
'--toggle-- --toggle user_arg' \
4141
'1{/^toggle triggered/d}' \
4242
'/^INVALID OPTION/d'
43-
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset'
44-
expect "${bash_getopts[2]}" == 'INVALID OPTION -- OPTARG=-'
45-
expect "${bash_getopts[3]}" == 'INVALID OPTION -- OPTARG=-'
46-
expect "${bash_getopts[4]}" == 'toggle triggered -- OPTARG is unset'
47-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=toggle--'
48-
expect "${getopts_long[2]}" == 'toggle triggered -- OPTARG is unset'
43+
expect "${bash_getopts[2]}" == 'INVALID OPTION -- OPTARG="-"'
44+
expect "${bash_getopts[3]}" == 'INVALID OPTION -- OPTARG="-"'
45+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="toggle--"'
46+
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG'
47+
expect "${bash_getopts[4]}" == 'toggle triggered -- OPTARG'
48+
expect "${getopts_long[2]}" == 'toggle triggered -- OPTARG'
4949
}
5050
@test "${FEATURE}: long toggle, verbose" {
5151
compare '-t-- -t user_arg' \
@@ -55,12 +55,12 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-shortspec_with_dash'
5555
'5{/^INVALID OPTION or MISSING ARGUMENT/d}' \
5656
's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' \
5757
's/(illegal option --) (-|toggle--)/\1 TOGGLE-NORMALISED/'
58-
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset'
58+
expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG'
5959
expect "${bash_getopts[2]}" =~ 'getopts-verbose: illegal option -- -$'
6060
expect "${bash_getopts[4]}" =~ 'getopts-verbose: illegal option -- -$'
61-
expect "${bash_getopts[6]}" == 'toggle triggered -- OPTARG is unset'
61+
expect "${bash_getopts[6]}" == 'toggle triggered -- OPTARG'
6262
expect "${getopts_long[1]}" =~ 'getopts_long-\w+-verbose: illegal option -- toggle--$'
63-
expect "${getopts_long[3]}" == 'toggle triggered -- OPTARG is unset'
63+
expect "${getopts_long[3]}" == 'toggle triggered -- OPTARG'
6464
}
6565

6666
# Both implementations should see:
@@ -85,14 +85,14 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-shortspec_with_dash'
8585
compare '-o-- -t user_arg' \
8686
'--option-- --toggle user_arg' \
8787
'1{/(option supplied|INVALID OPTION)/d}'
88-
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
89-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=option--'
88+
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
89+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="option--"'
9090
}
9191
@test "${FEATURE}: long option, verbose" {
9292
compare '-o-- -t user_arg' \
9393
'--option-- --toggle user_arg' \
9494
'1{/(option supplied|illegal option)/d}' \
9595
'2{/^INVALID OPTION or MISSING ARGUMENT/d}'
96-
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
96+
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
9797
expect "${getopts_long[1]}" =~ "getopts_long-\w+-verbose: illegal option -- option--$"
9898
}

test/bats/github_26b.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-longspec_with_dash_colon'
1818
compare '-z' \
1919
'---zz' \
2020
'/^INVALID OPTION/d'
21-
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG=z'
22-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=-zz'
21+
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG="z"'
22+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="-zz"'
2323
}
2424
@test "${FEATURE}: option with adjacent value, verbose" {
2525
compare '-z' \

test/bats/invalid_arguments.bats

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ load ../test_helper
1616
compare '-i' \
1717
'--invalid' \
1818
'/^INVALID OPTION -- /d'
19-
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG=i'
20-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=invalid'
19+
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG="i"'
20+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="invalid"'
2121
}
2222
@test "${FEATURE}: long option, verbose" {
2323
compare '-i' \
@@ -41,8 +41,8 @@ load ../test_helper
4141
compare '-i user_arg' \
4242
'--invalid user_arg' \
4343
'/^INVALID OPTION -- /d'
44-
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG=i'
45-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=invalid'
44+
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG="i"'
45+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="invalid"'
4646
}
4747
@test "${FEATURE}: long option, extra arguments, verbose" {
4848
compare '-i user_arg' \
@@ -68,8 +68,8 @@ load ../test_helper
6868
compare '-i -- user_arg' \
6969
'--invalid -- user_arg' \
7070
'/^INVALID OPTION -- /d'
71-
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG=i'
72-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=invalid'
71+
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG="i"'
72+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="invalid"'
7373
expect "${getopts_long[6]}" == '$@: user_arg'
7474
}
7575
@test "${FEATURE}: long option, terminator, extra arguments, verbose" {

test/bats/option_supplied.bats

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,27 @@ load ../test_helper
6969
@test "${FEATURE}: short option, multiple same arguments, silent" {
7070
compare '-o user_val1 -o user_val2' \
7171
'-o user_val1 -o user_val2'
72-
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
73-
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
72+
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val1"'
73+
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val2"'
7474
}
7575
@test "${FEATURE}: short option, multiple same arguments, verbose" {
7676
compare '-o user_val1 -o user_val2' \
7777
'-o user_val1 -o user_val2'
78-
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
79-
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
78+
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val1"'
79+
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val2"'
8080
}
8181

8282
@test "${FEATURE}: long option, multiple same arguments, silent" {
8383
compare '-o user_val1 -o user_val2' \
8484
'--option user_val1 --option user_val2'
85-
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
86-
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
85+
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val1"'
86+
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val2"'
8787
}
8888
@test "${FEATURE}: long option, multiple same arguments, verbose" {
8989
compare '-o user_val1 -o user_val2' \
9090
'--option user_val1 --option user_val2'
91-
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
92-
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
91+
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val1"'
92+
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val2"'
9393
}
9494

9595
# terminator followed by options
@@ -134,8 +134,8 @@ load ../test_helper
134134
compare '-o' \
135135
'--option' \
136136
'/^MISSING ARGUMENT -- /d'
137-
expect "${bash_getopts[1]}" == 'MISSING ARGUMENT -- OPTARG=o'
138-
expect "${getopts_long[1]}" == 'MISSING ARGUMENT -- OPTARG=option'
137+
expect "${bash_getopts[1]}" == 'MISSING ARGUMENT -- OPTARG="o"'
138+
expect "${getopts_long[1]}" == 'MISSING ARGUMENT -- OPTARG="option"'
139139
}
140140
@test "${FEATURE}: long option, missing value, verbose" {
141141
compare '-o' \
@@ -198,8 +198,8 @@ load ../test_helper
198198
compare '-ouser_val' \
199199
'--optionuser_val' \
200200
'1d'
201-
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=user_val'
202-
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=optionuser_val'
201+
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="user_val"'
202+
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="optionuser_val"'
203203

204204
}
205205

@@ -208,6 +208,6 @@ load ../test_helper
208208
'--optionuser_val' \
209209
'1d' \
210210
'2{/^INVALID OPTION or MISSING ARGUMENT/d}'
211-
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=user_val'
211+
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="user_val"'
212212
expect "${getopts_long[1]}" =~ 'getopts_long-verbose: illegal option -- optionuser_val'
213213
}

test/bats/toggle_triggered.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,26 @@ load ../test_helper
7070
compare '-t -t' \
7171
'-t -t'
7272
expect "${getopts_long[1]}" == "${getopts_long[2]}"
73-
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset'
73+
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG'
7474
}
7575
@test "${FEATURE}: short option, multiple same arguments, verbose" {
7676
compare '-t -t' \
7777
'-t -t'
7878
expect "${getopts_long[1]}" == "${getopts_long[2]}"
79-
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset'
79+
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG'
8080
}
8181

8282
@test "${FEATURE}: long option, multiple same arguments, silent" {
8383
compare '-t -t' \
8484
'--toggle --toggle'
8585
expect "${getopts_long[1]}" == "${getopts_long[2]}"
86-
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset'
86+
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG'
8787
}
8888
@test "${FEATURE}: long option, multiple same arguments, verbose" {
8989
compare '-t -t' \
9090
'--toggle --toggle'
9191
expect "${getopts_long[1]}" == "${getopts_long[2]}"
92-
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset'
92+
expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG'
9393
}
9494

9595
# terminator followed by options

test/bats/value_supplied.bats

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,31 @@ load ../test_helper
8787
@test "${FEATURE}: short option, multiple same arguments, silent" {
8888
compare '-v user_val1 -v user_val2' \
8989
'-v user_val1 -v user_val2'
90-
expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1'
91-
expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2'
90+
expect "${getopts_long[1]}" == 'value supplied -- OPTARG="user_val1"'
91+
expect "${getopts_long[2]}" == 'value supplied -- OPTARG="user_val2"'
9292
}
9393
@test "${FEATURE}: short option, multiple same arguments, verbose" {
9494
compare '-v user_val1 -v user_val2' \
9595
'-v user_val1 -v user_val2'
96-
expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1'
97-
expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2'
96+
expect "${getopts_long[1]}" == 'value supplied -- OPTARG="user_val1"'
97+
expect "${getopts_long[2]}" == 'value supplied -- OPTARG="user_val2"'
9898
}
9999

100100
@test "${FEATURE}: long option, multiple same arguments, silent" {
101101
compare '-v user_val1 -v user_val2' \
102102
'--variable=user_val1 --variable=user_val2' \
103103
'/^OPTIND: /d'
104-
expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1'
105-
expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2'
104+
expect "${getopts_long[1]}" == 'value supplied -- OPTARG="user_val1"'
105+
expect "${getopts_long[2]}" == 'value supplied -- OPTARG="user_val2"'
106106
expect "${bash_getopts[6]}" == 'OPTIND: 5'
107107
expect "${getopts_long[6]}" == 'OPTIND: 3'
108108
}
109109
@test "${FEATURE}: long option, multiple same arguments, verbose" {
110110
compare '-v user_val1 -v user_val2' \
111111
'--variable=user_val1 --variable=user_val2' \
112112
'/^OPTIND: /d'
113-
expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1'
114-
expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2'
113+
expect "${getopts_long[1]}" == 'value supplied -- OPTARG="user_val1"'
114+
expect "${getopts_long[2]}" == 'value supplied -- OPTARG="user_val2"'
115115
expect "${bash_getopts[6]}" == 'OPTIND: 5'
116116
expect "${getopts_long[6]}" == 'OPTIND: 3'
117117
}
@@ -158,8 +158,8 @@ load ../test_helper
158158
compare '-v' \
159159
'--variable' \
160160
'/^MISSING ARGUMENT -- /d'
161-
expect "${bash_getopts[1]}" == 'MISSING ARGUMENT -- OPTARG=v'
162-
expect "${getopts_long[1]}" == 'MISSING ARGUMENT -- OPTARG=variable'
161+
expect "${bash_getopts[1]}" == 'MISSING ARGUMENT -- OPTARG="v"'
162+
expect "${getopts_long[1]}" == 'MISSING ARGUMENT -- OPTARG="variable"'
163163
}
164164
@test "${FEATURE}: long option, missing value, verbose" {
165165
compare '-v' \

test/bin/getopts-silent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ while getopts ":to:v:" OPTKEY; do
2222
;;
2323
esac
2424
printf ' -- '
25-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
25+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
2626
done
2727

2828
shift $(( OPTIND - 1 ))

test/bin/getopts-verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ while getopts "to:v:" OPTKEY; do
1919
;;
2020
esac
2121
printf ' -- '
22-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
22+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
2323
done
2424

2525
shift $(( OPTIND - 1 ))

test/bin/getopts_long-github_26-silent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ while getopts_long ':to:v: toggle option: variable: -toggle -option:' OPTKEY; do
2626
;;
2727
esac
2828
printf ' -- '
29-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
29+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
3030
done
3131

3232
shift $(( OPTIND - 1 ))

test/bin/getopts_long-github_26-verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ while getopts_long 'to:v: toggle option: variable: -toggle -option:' OPTKEY; do
2323
;;
2424
esac
2525
printf ' -- '
26-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
26+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
2727
done
2828

2929
shift $(( OPTIND - 1 ))

test/bin/getopts_long-longspec_with_dash-silent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ while getopts_long ':to:v: - toggle option: variable:' OPTKEY; do
2626
;;
2727
esac
2828
printf ' -- '
29-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
29+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
3030
done
3131

3232
shift $(( OPTIND - 1 ))

test/bin/getopts_long-longspec_with_dash-verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ while getopts_long 'to:v: - toggle option: variable:' OPTKEY; do
2323
;;
2424
esac
2525
printf ' -- '
26-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
26+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
2727
done
2828

2929
shift $(( OPTIND - 1 ))

test/bin/getopts_long-longspec_with_dash_colon-silent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ while getopts_long ':to:v: -: toggle option: variable:' OPTKEY; do
2626
;;
2727
esac
2828
printf ' -- '
29-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
29+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
3030
done
3131

3232
shift $(( OPTIND - 1 ))

test/bin/getopts_long-longspec_with_dash_colon-verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ while getopts_long 'to:v: -: toggle option: variable:' OPTKEY; do
2323
;;
2424
esac
2525
printf ' -- '
26-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
26+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
2727
done
2828

2929
shift $(( OPTIND - 1 ))

test/bin/getopts_long-no_shortspec-silent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ while getopts_long ': toggle option: variable:' OPTKEY; do
2626
;;
2727
esac
2828
printf ' -- '
29-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
29+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
3030
done
3131

3232
shift $(( OPTIND - 1 ))

test/bin/getopts_long-no_shortspec-verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ while getopts_long ' toggle option: variable:' OPTKEY; do
2323
;;
2424
esac
2525
printf ' -- '
26-
[[ -z "${OPTARG+SET}" ]] && echo 'OPTARG is unset' || echo "OPTARG=${OPTARG}"
26+
declare -p OPTARG 2>&1 | grep -oe 'OPTARG.*'
2727
done
2828

2929
shift $(( OPTIND - 1 ))

0 commit comments

Comments
 (0)