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
11 changes: 11 additions & 0 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7165,6 +7165,17 @@ impl Interpreter {
} else {
result.push_str(&expanded);
}
} else if let Some(&c) = chars.peek()
&& matches!(c, '#' | '?' | '$' | '!' | '@' | '*' | '-')
{
// Handle special variables: $#, $?, $$, $!, $@, $*, $-
chars.next();
let value = self.expand_variable(&c.to_string());
if value.is_empty() {
result.push('0');
} else {
result.push_str(&value);
}
} else {
// Handle $var syntax (common in arithmetic)
let mut name = String::new();
Expand Down
23 changes: 23 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/arithmetic.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,26 @@ echo $x
### expect
42
### end

### arith_special_var_hash
# $# in arithmetic context
set -- a b c
echo "argc: $#"
(( $# > 0 )) && echo "true" || echo "false"
(( 3 > 0 )) && echo "true2" || echo "false2"
x=$#
(( x > 0 )) && echo "true3" || echo "false3"
### expect
argc: 3
true
true2
true3
### end

### arith_special_var_question
# $? in arithmetic context
true
(( $? == 0 )) && echo "zero" || echo "nonzero"
### expect
zero
### end
Loading