Can I use
getopts for parsing command-line arguments in my
sh) without worrying about another depedency?
$ type getopts
getopts is a shell builtin
getopts is built in, so it's present anywhere bash is.
To be sure of that you'd need to check the bash documentation to see whether it's an optional feature — it isn't.
More precisely, this tells you that
getopts is available in this particular version of bash. You need to check the release notes for older versions to see when
getopts was introduced; that happened before the dawn of time (it was already present in bash 1.14 and you'd have a hard time finding a version that old).
Even better, you can count on
getopts even in shells that aren't bash, since it's required by POSIX.
man getopts. Even though
getopts is a program in
/usr/bin You can see that it redirects you to a list of builtin bash commands
BASH_BUILTINS(1) and that the bash documentation specifically refers to
getopts optstring name [args]
For more detailed usage of how to use getopts see "example of how to use getopts in bash"