bash-oo-framework
bash-oo-framework copied to clipboard
Not running on bash <= 4.1
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] ...]
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 [email protected] 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 https://github.com/niieani/bash-oo-framework/issues/16.
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
-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.
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.
Ah, cool. Did you manage to get console logging running?
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 && (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."
Cool, thanks for investigating!
Will this get integrated into the next release?
@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.