bash-argsparse
bash-argsparse copied to clipboard
Doesn't appear to work with MacOS "brew" port of bash
I've tried running one of the tutorial scripts and it does not successfully parse options on MacOS via "homebrew" installation of Bash version 5.2.37, however it does on an ubuntu VM which has bash 5.1.16.
I'm not sure if this is an issue with Bash 5.2.37 or Mac homebrew build specifically at this time. Happy to provide other details as needed. Thanks.
#MacOS screenshot
#Ubuntu
Thanks for the report, I'll dig into that.
I cannot reproduce it on fedora 42 with bash 5.2.37
[anvil@krampouz ~/git/bash-argsparse]# bash tutorial/1-basics -o 1
Options reporting:
option2 : yes (1)
option3 : no
option1 : no
option4 : no
help : no
End of argsparse report.
option1 was not on the command line.
option2 was set 1 time(s) on the command line.
option3 was not on the command line.
option4 was not on the command line.
Parameter #1: 1
GNU bash, version 5.2.37(1)-release (x86_64-redhat-linux-gnu)
My guess right now is that you're not using GNU getopt. Can you confirm?
I cannot reproduce it on fedora 42 with bash 5.2.37
[anvil@krampouz ~/git/bash-argsparse]# bash tutorial/1-basics -o 1 Options reporting: option2 : yes (1) option3 : no option1 : no option4 : no help : no End of argsparse report. option1 was not on the command line. option2 was set 1 time(s) on the command line. option3 was not on the command line. option4 was not on the command line. Parameter #1: 1GNU bash, version 5.2.37(1)-release (x86_64-redhat-linux-gnu)My guess right now is that you're not using GNU getopt. Can you confirm?
I believe MacOS is using the BSD equivalent but will need to dig into that further,.
By default, yes, Mac has indeed a non-GNU version.
Unfortunately it looks like homebrew doesn't install getopt on the $PATH when installing gnu-getopt. You need to go look for it in $(brew --prefix gnu-getopt)/bin/getopt.
I assume that putting it on the $PATH breaks other stuff on macOS so that's why they don't do it.
So, if I understandand correctly, this is an OS / user configuration isssue. You would need to PATH=$(brew --prefix gnu-getopt):$PATH in your script before sourcing argsparse.
To support macOS it seems that, as it is, users would have to brew install gnu-getopt and scripts using bash-argsparse would have to have something like PATH=$(brew --prefix gnu-getopt):$PATH for it to run properly.
I would suggest adding support for FLAGS_GETOPT_CMD as some other scripts have done to allow users to specify the location of getopt for compatibility's sake. shflags is an example. Users and/or scripts could set this and bash-argsparse would use it to run getopts if set.
I'd personally like to keep it off the PATH if possible, but FLAGS_GETOPT_CMD seems mostly like a shflags thing so it's your call really.
getopts is not a getopt. it's a built-in and it's out of the question. Let's add an ARGSPARSE_GNU_GETOPT={ARGSPARSE_GNU_GETOPT:-getopt}.
This okay with you ?