niieani/bash-oo-framework

Aliases not supported in older versions of BASH.

JaredTS486 opened this issue · 0 comments

Aliases are simply not supported by the legacy Bourne shell which predates functions. There is no point trying to define and execute an alias under /sbin/sh or /bin/sh when running Solaris 10 and older. The Solution again is to determine the current OS and decide whether to use the Alias or Function.

Possible incomplete solution, declare if older bash detected.
if [[ "${BASH_VERSION:0:1}" -lt 4 ]] ; then
P="x"
declare -${P} import="System::Import"
declare -${P} source="__oo__allowFileReloading=true System::ImportOne"
declare -${P} .="__oo__allowFileReloading=true System::ImportOne"
else
P="g"
alias import="System::Import"
alias source="__oo__allowFileReloading=true System::ImportOne"
alias .="__oo__allowFileReloading=true System::ImportOne"
fi

Replace import with ${import:-import}
Should use import if value not null or literal "import" if null and alias is available.

Side issue:
declare -${P} .="__oo__allowFileReloading=true System::ImportOne" causes error: .../lib/oo-bootstrap.sh: line 11: declare: `.=__oo__allowFileReloading=true System::ImportOne': not a valid identifier