getopts(1) on Solnix vs Linux and the BSDs
On a default Solnix system getopts is the illumos /usr/bin/getopts, and the illumos page also documents the sh, ksh and ksh93 built-ins. The FreeBSD getopts(1) page is only the index of shell built-ins, so the bundle gives no FreeBSD getopts behaviour to compare. The main documented Solnix difference is that the ksh built-in supports long options such as getopts "f(file)" opt.
The manual pages
- Solnix: getopts(1) from
pkgs.solnix.illumos-world-man· illumos.org - FreeBSD: getopts(1) 15.1-RELEASE
- Standard: POSIX.1-2024 (IEEE Std 1003.1-2024),
getopts
What Solnix runs
A default Solnix system runs the illumos getopts at /usr/bin/getopts. /usr/xpg4/bin/getopts is also shipped; the bundle does not say how it differs. The page also describes the getopts built-ins of sh, ksh and ksh93. The ksh93 synopsis adds [-a name]. The page recommends getopts over getopt and mentions /usr/lib/getoptcvt, which converts scripts from getopt to getopts. The bundle has no Linux, OpenBSD or NetBSD getopts text.
Differences
| Compared with | Topic | What differs |
|---|---|---|
| FreeBSD | what the FreeBSD page covers | FreeBSD getopts(1) is a shared index of csh(1) and sh(1) built-ins, not a getopts description. It lists getopts as a sh(1) built-in, not a csh(1) one, and not a standalone utility. It has no option-parsing details to compare. Source: FreeBSD getopts(1) NAME, DESCRIPTION, Commands table (getopts: No*, No, Yes); Solnix getopts(1) DESCRIPTION |
| FreeBSD | standalone getopts command | The FreeBSD table marks getopts 'No*': it exists externally but is a script around the built-in. Solnix ships /usr/bin/getopts and /usr/xpg4/bin/getopts. The bundle does not say whether the Solnix files are scripts.Source: FreeBSD getopts(1) Commands table and No* note; Solnix getopts(1) SYNOPSIS |
| all four | long options in ksh getopts | The Solnix ksh getopts accepts long options written in parentheses after the short option, for example getopts "f(file)" opt. --file or ++file on the command line then maps to -f or +f, and name is set to the short option. The bundle does not document this for any counterpart.Source: Solnix getopts(1) ksh section (CLIP long options, "f(file)") |
| all four | + options in ksh getopts | The Solnix ksh getopts treats arguments starting with + as options as well as those starting with -. It prepends + to the option letter placed in name when the argument began with +. The bundle shows no counterpart doing this. Source: Solnix getopts(1) ksh section (option begins with + or -) |
| all four | ksh93 -a name | The ksh93 synopsis of Solnix getopts takes an optional -a name before optstring. The visible text does not explain what -a does, because the page is trimmed.Source: Solnix getopts(1) SYNOPSIS (ksh93) |
| all four | errors and leading colon | On Solnix, an unknown option sets name to ? and a missing option-argument sets it to ?. If optstring starts with a colon, a missing argument sets name to : and OPTARG to the option character, with no stderr message. Without the colon, a diagnostic is written to stderr. Source: Solnix getopts(1) DESCRIPTION (/usr/bin/getopts and ksh sections) |
| all four | exit status at end of options | On Solnix, getopts returns a value greater than zero when it reaches the end of options, and sets name to ?. An invalid option or missing argument is not a getopts processing error, so the exit status is zero in those cases. Source: Solnix getopts(1) DESCRIPTION (end of options; missing option-argument) |
| all four | resetting OPTIND | On Solnix, a script may parse a new parameter set only by setting OPTIND to 1. Any other change to OPTIND, or different arguments across calls, gives unspecified results. Source: Solnix getopts(1) DESCRIPTION (OPTIND set to the value 1) |
| all four | deprecated syntax relaxations | Solnix sh getopts still accepts grouping an option that takes an argument with other options (-aboxxx) and no white space before the option-argument. The page says not to use these because future releases may not support them.Source: Solnix getopts(1) sh section (Rule 5 and Rule 6 examples) |
Standards
- POSIX: getopts is a POSIX.1-2024 utility.
- Solnix: The page says getopts supports all applicable rules of the command syntax standard (Rules 3-10, Intro(1)). The ATTRIBUTES section is not in the trimmed bundle.
- FreeBSD: The FreeBSD page, as trimmed here, has no standards statement for getopts.
Writing portable scripts
- Use only single-character options and a plain optstring in portable scripts. Long options in parentheses and + options are documented only for the Solnix ksh getopts.
- Do not rely on OPTIND after setting it to anything but 1. Put a leading colon in optstring if you want to print your own error messages.
Every difference here is taken from the manual pages linked above: Solnix's published page, Linux (man-pages and the GNU and util-linux manuals), FreeBSD, OpenBSD and NetBSD. Each row names its source. Where a manual is silent, this page is too. Compiled 2026-10-26. Found a mistake? Mail hackers@lists.solnix.io.