4 ms·
>Bash is a near-dead/dying language in the sense that OSX is pushing zsh, and there are some fundamental flaws in bash that are difficult to consistently work a
by twofornone 5y ago
>Bash is a near-dead/dying language in the sense that OSX is pushing zsh, and there are some fundamental flaws in bash that are difficult to consistently work around (eg: see bash-pitfalls and shellcheck).
Recently tried my hand at some bash on osx and was frustrated to find that the osx version of getopt does not support long options, so it looks like there's no portable way to conveniently handle long options on osx, and forcing users to install GNU getopt kind of defeats the purpose of bash (portability)?
I guess I don't know the standard, is it reasonable to bundle in a dependency download with a simple bash script (e.g. download the correct version of getopt before parsing args)? I imagine not.
How does one properly support long and short options in bash on osx without rolling your own parser?
- rascul 5y ago> frustrated to find that the osx version of getopt does not support long options Probably best not to use getopt, but use getopts instead. In bash, getopts is a builtin. See the link below. http://mywiki.wooledge.org/ComplexOptionParsing#util-linux.27s_special_getopt http://mywiki.wooledge.org/ComplexOptionParsing#util-linux.2...
- 0xbadcafebee 5y agogetopts is actually POSIX so all POSIX-compatible shells should have it. Looks like zsh does: https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Command... For anyone new to parsing args with getopts, a guide like this might help: https://www.shellscript.sh/tips/getopts/ https://www.shellscript.sh/tips/getopts/