Artificial intelligent assistant

Which is the more standard package, getopt or getopts (with an "s")? The Linux foundation list of standard utilities includes `getopts` but not `getopt`. Similar for the Open Group list of Posix utilities. Meanwhile, Wikipedia's list of standard Unix Commands includes `getopt` but not `getopts`. Similarly, the Windows Subsystem for Linux (based on Ubuntu based on Debian) also includes `getopt` but not `getopts` (and it is the GNU Enhanced version)). balter@spectre:~$ which getopt /usr/bin/getopt balter@spectre:~$ getopt -V getopt from util-linux 2.27.1 balter@spectre:~$ which getopts balter@spectre:~$ So if I want to pick one that I can be the most confident that anyone using one of the more standard Linux distros (e.g. Debian, Red Hat, Ubuntu, Fedora, CentOS, etc.), which should I pick? ### Note: thanks to Michael and Muru for explaining about builtin vs executable. I had just stumbled across this as well which lists bash builtins.

`which` is the wrong tool. `getopts` is usually also a builtin:

> Since `getopts` affects the current shell execution environment, it is generally provided as a shell regular built-in.


~ for sh in dash ksh bash zsh; do "$sh" -c 'printf "%s in %s\
" "$(type getopts)" "$0"'; done
getopts is a shell builtin in dash
getopts is a shell builtin in ksh
getopts is a shell builtin in bash
getopts is a shell builtin in zsh


If you're using a shell script, you can safely depend on `getopts`. There might be other reasons to favour one or the other, but `getopts` is _standard_.

See also: Why not use "which"? What to use then?

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 635dbb0cbf864a2285ff77f8d86211c7