albfan / bash-ini-parser

GNU General Public License v3.0
141 stars 46 forks source link

Doesn't work in Mac OS X BASH #8

Closed mercury00 closed 4 years ago

mercury00 commented 8 years ago

Hi, the bash parameter substitutions in cfg_parser don't work in Mac OS X and the script crashes.

Namely, the grouping () operators don't do anything in:

ini=( ${ini[*]/#+([[:space:]])/} ) # remove init whitespace

ini=( ${ini[_]/_([[:space:]])=*([[:space:]])/=} ) # remove whitespace around =

For the second one, this /does/ seem to work in mac os x, but not if you haven't stripped initial whitespace or it will also remove the variable name, I'm currently stumped as to getting bash in Mac OS X to strip initial whitespace:

ini=( ${ini[_]/=_[[:space:]]/=})
ini=( ${ini[_]/[[:space:]]_=/=})

two separate operations - the * operator doesn't seem to operate as a "match character" in os x at all, but like it would on the command line itself, it just matches /anything/ like a wildcard.

I don't yet see a way for Mac OS X Bash to operate like Linux Bash.

albfan commented 8 years ago

What is your bash version?

$ bash --version

Can you run test suite and post here results?

$ cd t
$ make

or

$ make DEFAULT_TEST_TARGET=tap SHELL=/bin/bash

Can you comment this line:

https://github.com/albfan/bash-ini-parser/blob/master/bash-ini-parser#L8

And post here the verbose output from test suite too?

mercury00 commented 8 years ago

Sorry for the delay. I'll try this out. FYI, Mac OS X is locked into bash 3.x something, even with the latest OS X El Capitan (10.11.3)

I got: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15) Copyright (C) 2007 Free Software Foundation, Inc.

I'll run the test suite and let you know.

I used this in a bash script on linux hosts and it worked fine, fyi, but was trying to develop my code on an apple.

albfan commented 8 years ago

Great news. I have access to a mountain lion, and it has bash 3.x too.

Support on mac is a wanted feature. I did work on these issue , but trying to upgrade to el capitan. If it is not really needed I will try to fix on that mac os.

albfan commented 8 years ago

Any progress? I want to solve this but if you find out something, comment please

dukechem commented 7 years ago

homebrew will install newest 4.x bash in /usr/local/bin (in any of the 2 or 3 most recent osx versions): brew install bash Then /usr/local/bin/bash --version

mercury00 commented 7 years ago

I don't find installing homebrew, fink, or macports a solution to this as it just creates a new dependency (and lots of ported libraries). I would think some if/then testing bash versions might work though.

albfan commented 7 years ago

I try this with a bash 3.2 https://aur.archlinux.org/packages/bash3/ and using shopt -s compat32 in a bash 4.4 and it works. I have to do the test I mentioned inside a mac.

alvations commented 7 years ago

It's kind of extreme but I had to install noah to get bash-ini-parser to work on Mac

brew tap linux-noah/noah
brew install noah

Then:

noah
. bash-ini-parser
cfg_parser file.in
cfg_section_section
echo $key
albfan commented 6 years ago

I get access to a "El capitan" OS. can confirm that replace around = is not working, * seems to be non greedy. So replacing in to steps +([[:space:]])= and =+([[:space:]]) should work to replace 4 possible cases:

" = "
" ="
"= "
"="

Wanting to fix this one. Hope to do so in next days. By now a work around will be to remove whitespace around =

albfan commented 6 years ago

I have added CI for Mac

https://travis-ci.org/albfan/bash-ini-parser/jobs/397658828

PR welcomed!

albfan commented 4 years ago

Reviewing all this again. Let's see if I can fix it now

albfan commented 4 years ago

Should be fixed on master. Thanks for reporting!