Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use more readable empty-string tests #880

Merged
merged 1 commit into from
May 3, 2024

Conversation

LucasLarson
Copy link
Owner

@LucasLarson LucasLarson commented May 3, 2024

replace:1

  • test -n "${variable}" with test "${variable}" != '', and
  • test -z "${variable}" with test "${variable}" = ''

Footnotes

  1. Safe ways to do things in bash § empty string comparisons by Andreas Nordal

replace:
- `test -n "${variable}"` with `test "${variable}" != ''`, and
- `test -z "${variable}"` with `test "${variable}" = ''`

https://github.com/anordal/shellharden/blob/35411af8d466fb8b75f9769c7bf4bcc0cb2a2920/how_to_do_things_safely_in_bash.md#are-empty-string-comparisons-any-special

Signed-off-by: Lucas Larson <[email protected]>
@LucasLarson LucasLarson added the enhancement New feature or request label May 3, 2024
@LucasLarson LucasLarson marked this pull request as ready for review May 3, 2024 13:21
@LucasLarson LucasLarson merged commit 59f8cc3 into main May 3, 2024
6 checks passed
@LucasLarson LucasLarson deleted the empty-string_test_readability branch May 3, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant