bash-argsparse icon indicating copy to clipboard operation
bash-argsparse copied to clipboard

Doesn't appear to work with MacOS "brew" port of bash

Open fdx-apdewis opened this issue 7 months ago • 4 comments

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 Image

#Ubuntu

Image

fdx-apdewis avatar Apr 09 '25 01:04 fdx-apdewis

Thanks for the report, I'll dig into that.

Anvil avatar Apr 13 '25 20:04 Anvil

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?

Anvil avatar Apr 13 '25 20:04 Anvil

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 believe MacOS is using the BSD equivalent but will need to dig into that further,.

fdx-apdewis avatar Apr 15 '25 06:04 fdx-apdewis

By default, yes, Mac has indeed a non-GNU version.

Anvil avatar Apr 30 '25 07:04 Anvil

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.

ianlewis avatar Nov 09 '25 23:11 ianlewis

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.

Anvil avatar Nov 12 '25 09:11 Anvil

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.

ianlewis avatar Nov 13 '25 01:11 ianlewis

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}.

Anvil avatar Nov 13 '25 08:11 Anvil

This okay with you ?

Anvil avatar Nov 13 '25 08:11 Anvil