URL: <https://savannah.gnu.org/support/?111340>
Summary: getopts POSIX compliance
Group: The GNU Bourne-Again SHell
Submitter: None
Submitted: Tue 18 Nov 2025 03:14:22 AM UTC
Category: None
Priority: 5 - Normal
Severity: 3 - Normal
Status: None
Privacy: Public
Assigned to: None
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Operating System: GNU/Linux
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Tue 18 Nov 2025 03:14:22 AM UTC By: Anonymous
First off, I know bash isn't POSIX-compliant by default. As I understand it,
though, it is like 99% so when running shell scripts with a /bin/sh shebang,
or when invoked with '--posix'. My understanding is also that dash intends to
be POSIX compliant, and should execute pretty much any POSIX-compliant script
in a POSIX-compliant manner, and therefore any significant behavioral
differences in bash in POSIX mode and dash as regards POSIX compliance are not
to be expected. With that said...
Given the following script (as `getopttest`)(I know this is not a minimal
example, sorry):
```
#!/bin/sh
f_flag=''
while getopts 'f' opt; do
case "$opt" in
f) f_flag=1; shift;;
*) >&2 echo "invalid option: -$OPTARG";;
esac
done
shift "$((OPTIND-1))"
printf '%s\n' "$@"
exit 0
```
Execution with bash:
$ bash --posix getopttest -f -- -t
getopttest: illegal option -- t
invalid option: -
Execution with dash:
$ dash getopttest -f -- -t
-t
I'm running bash 5.3.3 and dash 0.5.12.
As I understand the
[https://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html
POSIX] spec, dash's behavior is correct here, though I would expect bash to
behave the same way.
Is my understanding flawed or am I missing something really simple here?
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/support/?111340>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
