Skip to content

fix: make script compatible with bash 3.2 (macOS default)#1

Open
sanderversluys wants to merge 3 commits intomainfrom
fix/bash-3.2-compatibility
Open

fix: make script compatible with bash 3.2 (macOS default)#1
sanderversluys wants to merge 3 commits intomainfrom
fix/bash-3.2-compatibility

Conversation

@sanderversluys
Copy link

Summary

  • Fixes the declare: -A: invalid option error on macOS systems using the default bash 3.2
  • Replaces associative array (declare -A) with parallel indexed arrays and helper functions
  • The -A flag requires bash 4.0+, but macOS ships with bash 3.2.57 due to GPLv3 licensing

Changes

  • Replace PORT_ASSIGNMENTS associative array with PORT_ASSIGNMENT_KEYS and PORT_ASSIGNMENT_VALUES indexed arrays
  • Add helper functions: port_set, port_get, port_has, port_keys_sorted
  • Update all references throughout the script

Test plan

  • Test shipyard init on macOS with default bash 3.2
  • Test shipyard list to verify port assignments are saved/loaded correctly
  • Test on Linux with bash 4+ to ensure backwards compatibility

Replace associative array (declare -A) with parallel indexed arrays
and helper functions. The -A flag requires bash 4.0+, but macOS ships
with bash 3.2.57 due to GPLv3 licensing.

Changes:
- Replace PORT_ASSIGNMENTS associative array with PORT_ASSIGNMENT_KEYS
  and PORT_ASSIGNMENT_VALUES indexed arrays
- Add helper functions: port_set, port_get, port_has, port_keys_sorted
- Update all references throughout the script

This allows the script to run on stock macOS without requiring
users to install a newer bash version.
Use ${array[@]+"${array[@]}"} pattern to safely iterate over
potentially empty arrays when 'set -u' (nounset) is enabled.
readarray/mapfile is bash 4+. Use while read loop instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant