bashew icon indicating copy to clipboard operation
bashew copied to clipboard

Str:lower and others don't work out of the box on MacOS

Open Bertg opened this issue 3 years ago • 3 comments

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

  1. Clone bashew on a mac
  2. Create a script with bashew
  3. Attempt to run the command with an action (like env or check)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 awk for the Str methods (or only in the context of bash < 4)
  • Document the required bash version

Bertg avatar Sep 01 '22 21:09 Bertg

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
  }

Bertg avatar Sep 01 '22 21:09 Bertg

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 avatar Sep 05 '22 11:09 pforret

@pforret Bashly requires v4, I think that is also a valid strategy.

Bertg avatar Sep 05 '22 11:09 Bertg

bashew now will check for old bash versions (< 4) and quit

pforret avatar Oct 16 '22 17:10 pforret