Skip to content

_tests.sh script fails silently on macOS due to incompatible local -n usage #15

@a-magdy

Description

@a-magdy

Issue Description

The _tests.sh script fails silently when executed on macOS without providing clear error messages. After investigation, the issue appears to be related to the use of local -n (nameref) which is not supported in older versions of bash that ship with macOS.

Environment

  • Operating System: macOS
  • Default bash version: macOS typically ships with bash 3.x which doesn't support nameref (local -n)
  • Script: _tests.sh and git-artifact

Error Details

When running the test script, it fails with errors like:

myfunc:local:1: bad option: -n

Root Cause

The issue is caused by the usage of local -n (nameref) in the git-artifact script, which is called by _tests.sh. The nameref feature was introduced in bash 4.3, but macOS ships with bash 3.x by default for licensing reasons.

Problematic code locations in git-artifact:

  • Line 74: local -n _ref_dir=${1}
  • Line 87: local -n _ref_base_branch=${1}
  • Line 102: local -n _ref_remote_default_branch=${1}
  • Line 292: local -n _latest_tag=${1}

Impact

  • Tests fail silently on macOS
  • Users may not realize the script is not working properly
  • Makes development and testing difficult on macOS systems

Suggested Solutions

  1. Check bash version: Add a version check at the beginning of scripts to ensure bash 4.3+ is available
  2. Use alternative approaches: Replace nameref usage with return values or global variables
  3. Documentation: Add clear requirements about bash version in README
  4. Homebrew bash: Recommend users install a newer bash version via Homebrew

Workaround

Users can install a newer version of bash via Homebrew:

brew install bash

And then either:

  • Update their PATH to use the newer bash
  • Explicitly run scripts with the newer bash: /usr/local/bin/bash _tests.sh

Additional Context

This is a common issue when developing bash scripts that need to work across different platforms, as macOS deliberately ships with an older bash version to avoid GPL v3 licensing requirements.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions