fix(interpreter): expand array args as separate fields#201
Conversation
"${arr[@]}" was joining all elements with spaces into a single argument
instead of producing separate arguments. This broke printf format
repetition (e.g., `printf "%s\n" "${colors[@]}"` printed all on one line).
Root cause: execute_dispatched_command used expand_word which joins array
elements. Now uses expand_word_to_fields which preserves separate fields.
Also:
- Set word.quoted=true for QuotedWord tokens in parser (command args and
for-loop words) so "${arr[*]}" correctly joins into single field
- expand_word_to_fields distinguishes @ (separate fields) from * (joined
when quoted)
https://claude.ai/code/session_01AMR6sQEAyh5DXc13jvb9oK
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87fe6eccc5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for word in &command.args { | ||
| let expanded = self.expand_word(word).await?; | ||
| // Use field expansion so "${arr[@]}" produces multiple args | ||
| let fields = self.expand_word_to_fields(word).await?; |
There was a problem hiding this comment.
Preserve empty arg for quoted unset
${arr[*]}
Switching argument expansion to expand_word_to_fields here changes "${arr[*]}" when arr is unset from one empty argument to zero arguments, because the helper returns an empty vector for missing arrays. In bash, quoted * expansion still yields one field (e.g. f(){ echo $#; }; unset arr; f "${arr[*]}" prints 1), so this is a compatibility regression for functions/builtins that depend on argument count.
Useful? React with 👍 / 👎.
Summary
"${arr[@]}"expanding to a single space-joined argument instead of separate arguments for commands likeprintfword.quoted=trueforQuotedWordtokens in parser so"${arr[*]}"correctly joins elements into a single field while"${arr[@]}"produces separate fieldsexecute_dispatched_commandnow usesexpand_word_to_fieldsinstead ofexpand_wordfor argument expansionBefore:
printf "%s\n" "${colors[@]}"→Black Red Green Yellow Blue Magenta Cyan White(one line)After: Each color printed on its own line (bash-compatible)
Test plan
@expansion,*expansion, multi-format, single element; negative: empty array)@as args,*quoted,@unquoted)cargo test --all-features)cargo fmt --checkcleancargo clippy --all-targets --all-features -- -D warningsclean