Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3265,7 +3265,21 @@ impl Interpreter {
| WordPart::ArrayAccess { .. }
)
});
if is_unquoted_expansion {
// "${arr[@]}" or "$@" in array context should splat
// individual elements, not join into a single string.
let is_quoted_splat = word.quoted
&& word.parts.len() == 1
&& matches!(
&word.parts[0],
WordPart::ArrayAccess { index, .. } if index == "@"
);
let is_quoted_positional_splat = word.quoted
&& word.parts.len() == 1
&& matches!(
&word.parts[0],
WordPart::Variable(name) if name == "@"
);
if is_unquoted_expansion || is_quoted_splat || is_quoted_positional_splat {
let fields = self.expand_word_to_fields(word).await?;
all_fields.extend(fields);
} else {
Expand Down
22 changes: 22 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/array-splat.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### array_concat_at_expansion
# "${arr[@]}" in array literal should splat individual elements
a=(x y z)
b=(1 2)
c=("${a[@]}" "${b[@]}")
echo "${#c[@]}"
echo "${c[2]}"
### expect
5
z
### end

### array_splat_single_source
# Single "${arr[@]}" in array context
orig=(a b c d)
copy=("${orig[@]}")
echo "${#copy[@]}"
echo "${copy[3]}"
### expect
4
d
### end
Loading