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

fix: double quote array expansions to avoid re-splitting elements #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IgorShadurin
Copy link

In the deployment script, we identified an issue with the array expansion which could lead to unexpected behavior due to re-splitting of its elements.

Details:

  • Issue: We used an unquoted array expansion ${Files[@]}. If any of its elements contained spaces or other special characters, they would be re-split into separate arguments.
  • Fix: To prevent this, we've wrapped the array expansion in double quotes: "${Files[@]}".

This adheres to the recommendation from ShellCheck warning SC2068, which advises double-quoting array expansions to prevent globbing and word splitting of individual elements. Not doing so can lead to unexpected behavior, especially when elements of the array contain spaces or special characters.

Reference:

Problematic code:
cp $@ ~/dir

Correct code:
cp "$@" ~/dir

Rationale:
Double quotes around $@ (and similarly, ${array[@]}) prevent globbing and word splitting of individual elements, while still expanding to multiple separate arguments.

By applying this fix, we ensure the script behaves predictably and correctly, regardless of the content of the array elements.

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