News for hackers. Stuff that matters.
Re:Argbash: Bash argument parsing code generator by twofornone on Tuesday March 22, 2022 @12:24PM (#30768072)
>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?

Re:Argbash: Bash argument parsing code generator by rascul on Tuesday March 22, 2022 @12:31PM (#30768188)
> 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.2...

Re:Argbash: Bash argument parsing code generator by 0xbadcafebee on Tuesday March 22, 2022 @01:01PM (#30768612)
getopts is actually POSIX so all POSIX-compatible shells should have it. Looks like zsh does: 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/