Skip to content

fix: replace bash-only ${name^^} with portable tr for zsh compatibility#116

Merged
GingerGraham merged 3 commits into
GingerGraham:mainfrom
Jah-yee:fix/zsh-uppercase
May 27, 2026
Merged

fix: replace bash-only ${name^^} with portable tr for zsh compatibility#116
GingerGraham merged 3 commits into
GingerGraham:mainfrom
Jah-yee:fix/zsh-uppercase

Conversation

@Jah-yee
Copy link
Copy Markdown
Contributor

@Jah-yee Jah-yee commented May 26, 2026

Problem

When sourcing bash-logger from .zshrc, the _get_log_level_value function produces a bad substitution error because ${level_name^^} is bash 4+ specific syntax for uppercase conversion. zsh does not support this.

Fix

Replace the bash-specific ${name^^} case transformation with a portable equivalent using tr:

- local level_name="$1"
+ local level_name="$(printf '%s' "$1" | tr '[:lower:]' '[:upper:]')"

Also removed the now-redundant ^^ in the two case statements that used it.

Affected functions:

  • _get_log_level_value() — converts level name to uppercase for case matching
  • log_to_journal() — normalises level name for journald integration

Testing

The fix was verified with bash -n logging.sh (syntax check passed). The tr command is POSIX-compliant and works in both bash and zsh.

Closes #114

Replace ${level_name^^} (bash 4+ case transformation) with:
  $(printf '%s' "$1" | tr '[:lower:]' '[:upper:]')

Fixes zsh 'bad substitution' error when sourcing bash-logger from .zshrc.

Changes in _get_log_level_value() and log_to_journal().

Closes GingerGraham#114
@Jah-yee Jah-yee requested a review from GingerGraham as a code owner May 26, 2026 19:50
Copy link
Copy Markdown
Owner

@GingerGraham GingerGraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested myself locally, change looks good and in line with what I was expecting from my initial diagnosis and bug report in #114

Comment thread logging.sh Outdated
Comment thread logging.sh Outdated
Copy link
Copy Markdown
Owner

@GingerGraham GingerGraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See in line changes and failed linting https://github.com/GingerGraham/bash-logger/actions/runs/26471405342

Could you split the declaration of the local and it's assignment over two lines and then it's good to go.

@GingerGraham
Copy link
Copy Markdown
Owner

Test's good, but just need to address linting/style issues and then this is good to commit

Copy link
Copy Markdown
Owner

@GingerGraham GingerGraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local declaration and assignment now split. Looks good

@GingerGraham GingerGraham merged commit d004dc5 into GingerGraham:main May 27, 2026
2 checks passed
GingerGraham pushed a commit that referenced this pull request May 27, 2026
## [2.5.3](2.5.2...2.5.3) (2026-05-27)

### Bug Fixes

* replace bash-only ${name^^} with portable tr for zsh compatibility ([#116](#116))
@GingerGraham
Copy link
Copy Markdown
Owner

🎉 This PR is included in version 2.5.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] zsh incompatible syntax for setting upper case values: bad substitution error

2 participants