Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not running on bash <= 4.1 #16

Open
schabluk opened this issue Feb 15, 2016 · 9 comments
Open

Not running on bash <= 4.1 #16

schabluk opened this issue Feb 15, 2016 · 9 comments

Comments

@schabluk
Copy link

Have this error when running your-script.sh on Solaris.

$ uname -a
SunOS localhost 5.11 11.2 sun4v sparc sun4v
$ bash --version
GNU bash, version 4.1.17(1)-release (sparc-sun-solaris2.11)
$ ./your-script.sh
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 44: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 45: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 176: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 177: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 178: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 190: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]

@niieani
Copy link
Owner

niieani commented Feb 15, 2016

Hm, seems your version of bash doesn't have global variables (-g). If
possible, try bash>=4.2.
I'll try to figure out a workaround.
On Mon, 15 Feb 2016 at 09:50, Łukasz Schabek notifications@github.com
wrote:

Have this error when running your-script.sh on Solaris.

$ uname -a
SunOS deuxviqm 5.11 11.2 sun4v sparc sun4v
$ bash --version
GNU bash, version 4.1.17(1)-release (sparc-sun-solaris2.11)
$ ./your-script.sh
/pkg/vdcro/tools/bash-oo/lib/oo-bootstrap.sh: line 44: declare: -g:
invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/vdcro/tools/bash-oo/lib/oo-bootstrap.sh: line 45: declare: -g:
invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/vdcro/tools/bash-oo/lib/oo-bootstrap.sh: line 176: declare: -g:
invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/vdcro/tools/bash-oo/lib/oo-bootstrap.sh: line 177: declare: -g:
invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/vdcro/tools/bash-oo/lib/oo-bootstrap.sh: line 178: declare: -g:
invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/vdcro/tools/bash-oo/lib/oo-bootstrap.sh: line 190: declare: -g:
invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]


Reply to this email directly or view it on GitHub
#16.

@niieani niieani changed the title declare: -g: invalid option Not running on bash <= 4.1 Feb 17, 2016
@niieani niieani added this to the 2.5 milestone Feb 17, 2016
@JaredTS486
Copy link

JaredTS486 commented Feb 17, 2017

Declare -x is the other method for global variables.
I used the following on SunOS ${BASH_VERSION}=3.2.57(1)-release
[[ "${BASH_VERSION:0:1}" -lt 4 ]] && P="x" || P="g"
...
...
declare -${P} __oo__libPath="$( cd "${BASH_SOURCE[0]%/*}" && pwd )"
declare -${P} __oo__path="${__oo__libPath}/.."
declare -${P}a __oo__importedFiles

@niieani
Copy link
Owner

niieani commented Feb 17, 2017

-x exports the variables, that's not the same as making them global. The thing is, you can't export arrays or associative arrays, which is what the framework currently depends on. How much of the framework seemed to work under bash 3.2.57, @JaredTS486? I would imagine many parts to be broken without a proper porting process.

@JaredTS486
Copy link

That is true they are not the same but for bash 3.2 that is the only alternative and so far does the trick. I got most of the framework sourced without any errors after I changed the declares and modified the Aliases but made no direct function calls. Most recently I was working on log.sh attempting to use eval and indirect variable references to mimic the associative arrays. I manage scripts that run on both 3.2 and 4.2 so I know some methods for portability.

@niieani
Copy link
Owner

niieani commented Feb 17, 2017

Ah, cool. Did you manage to get console logging running?

@JaredTS486
Copy link

JaredTS486 commented Feb 21, 2017

I did but it required changing some major parts to Color.sh

declare/export only allow characters A-Z, a-z, 0-9, and _
So UI.Color.Default became UI_Color_Default etc...

Also had to change UI_Color_IsAvailable to a function that performs the same check.
UI_Color_IsAvailable(){ if $([ $(tput colors 2>/dev/null || echo 0) -ge 16 ] && [ -t 1 ]) ; then return 0 ; else return 1 ; fi }

Also:
UI_Powerline_IsAvailable(){ if UI_Color_IsAvailable && test -z $NO_UNICODE &amp;&amp; (echo -e $'\u1F3B7' | grep -v F3B7) &> /dev/null ; then return 0 ; else return 1 ; fi }

Then the call below seemed to work without errors.
Console::WriteStdErr "This will be printed to STDERR, no matter what."

@niieani
Copy link
Owner

niieani commented Feb 21, 2017

Cool, thanks for investigating!

@Tzrlk
Copy link

Tzrlk commented May 18, 2017

Will this get integrated into the next release?

@niieani
Copy link
Owner

niieani commented May 18, 2017

@Tzrlk I think a version supporting bash 3 would have to differ by quite a bit of modules, but I'd be up for supporting bash 4.0 in master if you wanna PR that. PR's welcome for both, we can keep the backwards compatible version in a bash-3 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants