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.

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 withTopicWhat differs
FreeBSDwhat the FreeBSD page coversFreeBSD 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
FreeBSDstandalone getopts commandThe 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 fourlong options in ksh getoptsThe 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 getoptsThe 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 fourksh93 -a nameThe 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 fourerrors and leading colonOn 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 fourexit status at end of optionsOn 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 fourresetting OPTINDOn 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 fourdeprecated syntax relaxationsSolnix 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.