docs: add bash array pattern for variadic args - #480
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 <noreply@anthropic.com>
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.
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)" |
There was a problem hiding this comment.
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.
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.
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
## 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 <noreply@anthropic.com>
### 🐛 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)
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [usage](https://github.com/jdx/usage) | minor | `2.15.1` → `2.16.1` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>jdx/usage (usage)</summary> ### [`v2.16.1`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#2161---2026-01-31) [Compare Source](jdx/usage@v2.16.0...v2.16.1) ##### 🐛 Bug Fixes - **(docs)** increase gap between feature grid and action buttons on landing page by [@​jdx](https://github.com/jdx) in [#​482](jdx/usage#482) - **(parse)** handle variadic ellipsis inside brackets like \[args...] by [@​jdx](https://github.com/jdx) in [#​481](jdx/usage#481) ##### 📚 Documentation - add bash array pattern for variadic args by [@​jdx](https://github.com/jdx) in [#​480](jdx/usage#480) ##### 📦️ Dependency Updates - update rust crate clap to v4.5.56 by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​474](jdx/usage#474) - update apple-actions/import-codesign-certs action to v6 by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​477](jdx/usage#477) - update dependency node to v24 by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​478](jdx/usage#478) - update rust crate criterion to 0.8 by [@​renovate\[bot\]](https://github.com/renovate\[bot]) in [#​475](jdx/usage#475) ### [`v2.16.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#2160---2026-01-29) [Compare Source](jdx/usage@v2.15.1...v2.16.0) ##### 🚀 Features - **(windows)** add Windows binaries and fix completion support by [@​jdx](https://github.com/jdx) in [#​472](jdx/usage#472) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45NC42IiwidXBkYXRlZEluVmVyIjoiNDIuOTUuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
## 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 jdx#6766 where users struggle
to handle variadic args with spaces in bash scripts.
Related:
- jdx#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 <noreply@anthropic.com>
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.