-
Notifications
You must be signed in to change notification settings - Fork 26
docs: add bash array pattern for variadic args #480
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
Conversation
Document how to properly convert variadic args to bash arrays using eval "arr=($usage_var)" pattern. This handles arguments with spaces correctly. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Summary of ChangesHello @jdx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the documentation by providing a new section that clarifies the process of handling variadic arguments in bash scripts. It specifically addresses the common challenge of correctly parsing arguments that contain spaces by providing a robust method for converting the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds documentation for handling variadic arguments in bash scripts, specifically addressing how to properly convert shell-escaped strings to bash arrays when arguments contain spaces.
Changes:
- Added a new section "Using Variadic Args in Bash" with code examples
- Documented the
eval "arr=($usage_var)"pattern for converting variadic args to bash arrays - Included usage examples for iterating over and passing array elements to commands
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Given: usage_files="arg1 'arg with space' arg3" | ||
|
|
||
| # Convert to bash array: | ||
| eval "files=($usage_files)" |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using eval with user-controlled input can introduce command injection vulnerabilities. If usage_files contains malicious shell commands, they will be executed. Consider documenting safer alternatives such as using readarray with process substitution, or add prominent security warnings about input validation if eval is necessary.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #480 +/- ##
=======================================
Coverage 70.57% 70.57%
=======================================
Files 47 47
Lines 6597 6597
Branches 6597 6597
=======================================
Hits 4656 4656
Misses 1264 1264
Partials 677 677 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds documentation for handling variadic arguments in Bash, particularly when arguments contain spaces. The suggested approach uses eval to create a Bash array. My feedback focuses on improving the security and robustness of the provided code example by mitigating the risks associated with eval, specifically by preventing unintended filename expansion (globbing).
| # Given: usage_files="arg1 'arg with space' arg3" | ||
|
|
||
| # Convert to bash array: | ||
| eval "files=($usage_files)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of eval here is vulnerable to globbing. If a user provides an argument like *, it will be expanded to a list of all files in the current directory, which can lead to unexpected behavior and security risks. To make this example safer for users to copy and paste, it's crucial to disable globbing before the eval command and restore it afterward.
| eval "files=($usage_files)" | |
| set -f # Disable globbing to prevent filename expansion | |
| eval "files=($usage_files)" | |
| set +f # Re-enable globbing |
References
- When using
evalto parse a string into shell arguments, it's important to disable globbing (set -f) to prevent unintended filename expansion from characters like*and?in the input string. This is a common security best practice for writing robust shell scripts.
Clarifies that readarray/mapfile are alternatives in bash 4.0+, but macOS ships with bash 3.2 by default which doesn't include them. The eval pattern works with all bash versions. Co-Authored-By: Claude Opus 4.5 <[email protected]>
readarray/mapfile don't understand shell quoting, so they wouldn't work with the current format regardless of bash version. Co-Authored-By: Claude Opus 4.5 <[email protected]>
## Summary
Documents how to properly convert variadic args (`var=#true`) to bash
arrays using the pattern:
```bash
eval "files=($usage_files)"
```
This handles arguments with spaces correctly.
## Changes
- Added tip box in the Variadic Arguments section explaining the pattern
- Added tip box after Example 4 in the migration guide showing the
complete pattern
## Example
```bash
# Convert to bash array:
eval "files=($usage_files)"
# Use as array:
for f in "${files[@]}"; do
echo "Processing: $f"
done
```
This addresses the common issue discussed in #6766 where users struggle
to handle variadic args with spaces in bash scripts.
Related:
- #6766
- jdx/usage#189
- jdx/usage#480
🤖 Generated with [Claude Code](https://claude.ai/code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk documentation-only change that adds usage guidance and
examples; no runtime or behavior changes.
>
> **Overview**
> Documents a recommended Bash pattern for variadic task args
(`var=#true`) that may include spaces, showing how to `eval
"files=($usage_files)"` and then consume the resulting array safely.
>
> Adds two new *tip* callouts: one in the `Variadic Arguments` section
and another in the migration guide’s variadic example, both providing
the same array-conversion snippet and usage examples.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
905ebdf. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>
### 🐛 Bug Fixes - **(docs)** increase gap between feature grid and action buttons on landing page by [@jdx](https://github.com/jdx) in [#482](#482) ### 📚 Documentation - add bash array pattern for variadic args by [@jdx](https://github.com/jdx) in [#480](#480) ### 📦️ Dependency Updates - update rust crate clap to v4.5.56 by [@renovate[bot]](https://github.com/renovate[bot]) in [#474](#474) - update apple-actions/import-codesign-certs action to v6 by [@renovate[bot]](https://github.com/renovate[bot]) in [#477](#477) - update dependency node to v24 by [@renovate[bot]](https://github.com/renovate[bot]) in [#478](#478) - update rust crate criterion to 0.8 by [@renovate[bot]](https://github.com/renovate[bot]) in [#475](#475)
Summary
Documents how to properly convert variadic args (
var=#true) to bash arrays using the pattern:This handles arguments with spaces correctly.
Example
This addresses the common issue where users struggle to handle variadic args with spaces in bash scripts.
Related: #189
🤖 Generated with Claude Code
Note
Low Risk
Documentation-only change; no runtime behavior is modified. Low risk aside from potentially encouraging unsafe
evalusage if misapplied.Overview
Adds a new “Using Variadic Args in Bash” section to
docs/spec/reference/arg.mddescribing howvar=#truevalues are exposed viausage_<name>and providing a Bash snippet (eval "files=($usage_files)") to safely iterate/pass variadic args that may contain spaces.Written by Cursor Bugbot for commit d23303c. This will update automatically on new commits. Configure here.