Str:lower and others don't work out of the box on MacOS
Describe the bug
Some of the Str functions don't work out of the box on MacOS, because of the older bash version that is installed by default.
The bash substitutions used only work from bash 4 and up.
To Reproduce
- Clone bashew on a mac
- Create a script with bashew
- Attempt to run the command with an action (like
envorcheck)4.
Output:
./bin/script: line 284: ${input,,}: bad substitution
Expected behavior
The command should just run
Desktop (please complete the following information):
- OS: MacOS 12.5.1
- bash version: 3.2
- Script version: 1.18.3
- copy/paste output of script.sh -v
# 🌼 Script path: ./bin/script
# 🌼 Linked path: ./bin/script
# 🌼 In folder : /Users/[redacted]/Code/[redacted]/bin
# 🌼 Shell type : bash - version 3.2.57(1)-release
# 🌼 System OS : macOS (Darwin) 12.5.1 on arm64
# 🌼 Package mgt: brew install
# 🌼 Version : 0.0.1
# 🌼 Created : 2022-09-01
# 🌼 Modified : Sep 1 23:35:53 2022
# 🌼 Lines : 1027 lines / md5: 5f99194d
# 🌼 User : [redacted]
# 🌼 git remote : [email protected]:[redacted]
# 🌼 git folder : /Users/[redacted]/Code/[redacted]
# 🌱 Read dotenv: [./.env]
# 🧽 Clean dotenv: [./.env.__.sh]
./.env.__.sh: line 39: YGcLOX15/Tu5Rrf7vcbZwnxvJPZLh8uvVUrQwg5sbG0bIoNtJDyEWVM=: No such file or directory
# 🌱 flag: verbose=1
# 🌱 Expect : 1 choice(s): action
⛔ script: need the choice(s) [action]
./bin/crdbrd: line 361: temp_files[@]: unbound variable
⛔ script: ERROR 1 after 0 seconds
> last command : 'Script:exit'
${error_prefix} from line 1020 : Option:parse "$@" # overwrite with specified options if any
./bin/script: line 361: temp_files[@]: unbound variable
Additional context
Note that the issue mentioned in #14 is present here as well
Suggestions
- Make sure that a minimal version of bash is present, if that is what is being relied on.
- Really solely on
awkfor theStrmethods (or only in the context of bash < 4) - Document the required bash version
My bash isn't so strong, but I think a fix like this may work:
function Str:lower() {
if [[ -n "$1" ]] ; then
local input="$*"
# echo "${input,,}"
echo $input | awk '{print tolower($0)}'
else
awk '{print tolower($0)}'
fi
}
Good point, I cannot assume people will always "brew upgrade" to a more recent version of bash. I just have to set up a testing environment for bash 3.2, I'm running bash 5 on all my machines.
@pforret Bashly requires v4, I think that is also a valid strategy.
bashew now will check for old bash versions (< 4) and quit