@@ -4392,11 +4392,9 @@ impl Interpreter {
43924392 if is_internal_variable ( var_name) {
43934393 continue ;
43944394 }
4395- // Handle compound array assignment: local -a arr=(1 2 3)
4396- if ( flags. array || flags. assoc )
4397- && value. starts_with ( '(' )
4398- && value. ends_with ( ')' )
4399- {
4395+ // Handle compound array assignment: local arr=(1 2 3) or local -a/-A arr=(...)
4396+ let is_compound = value. starts_with ( '(' ) && value. ends_with ( ')' ) ;
4397+ if is_compound {
44004398 let inner = & value[ 1 ..value. len ( ) - 1 ] ;
44014399 if flags. assoc {
44024400 let arr = self . assoc_arrays . entry ( var_name. to_string ( ) ) . or_default ( ) ;
@@ -4505,7 +4503,54 @@ impl Interpreter {
45054503 if is_internal_variable ( var_name) {
45064504 continue ;
45074505 }
4508- if flags. nameref {
4506+ let is_compound = value. starts_with ( '(' ) && value. ends_with ( ')' ) ;
4507+ if is_compound {
4508+ let inner = & value[ 1 ..value. len ( ) - 1 ] ;
4509+ if flags. assoc {
4510+ let arr = self . assoc_arrays . entry ( var_name. to_string ( ) ) . or_default ( ) ;
4511+ arr. clear ( ) ;
4512+ let mut rest = inner. trim ( ) ;
4513+ while let Some ( bracket_start) = rest. find ( '[' ) {
4514+ if let Some ( bracket_end) = rest[ bracket_start..] . find ( ']' ) {
4515+ let key = & rest[ bracket_start + 1 ..bracket_start + bracket_end] ;
4516+ let after = & rest[ bracket_start + bracket_end + 1 ..] ;
4517+ if let Some ( eq_rest) = after. strip_prefix ( '=' ) {
4518+ let eq_rest = eq_rest. trim_start ( ) ;
4519+ let ( val, remainder) =
4520+ if let Some ( stripped) = eq_rest. strip_prefix ( '"' ) {
4521+ if let Some ( end_q) = stripped. find ( '"' ) {
4522+ (
4523+ & stripped[ ..end_q] ,
4524+ stripped[ end_q + 1 ..] . trim_start ( ) ,
4525+ )
4526+ } else {
4527+ ( stripped. trim_end_matches ( '"' ) , "" )
4528+ }
4529+ } else {
4530+ match eq_rest. find ( char:: is_whitespace) {
4531+ Some ( sp) => {
4532+ ( & eq_rest[ ..sp] , eq_rest[ sp..] . trim_start ( ) )
4533+ }
4534+ None => ( eq_rest, "" ) ,
4535+ }
4536+ } ;
4537+ arr. insert ( key. to_string ( ) , val. to_string ( ) ) ;
4538+ rest = remainder;
4539+ } else {
4540+ break ;
4541+ }
4542+ } else {
4543+ break ;
4544+ }
4545+ }
4546+ } else {
4547+ let arr = self . arrays . entry ( var_name. to_string ( ) ) . or_default ( ) ;
4548+ arr. clear ( ) ;
4549+ for ( idx, val) in inner. split_whitespace ( ) . enumerate ( ) {
4550+ arr. insert ( idx, val. trim_matches ( '"' ) . to_string ( ) ) ;
4551+ }
4552+ }
4553+ } else if flags. nameref {
45094554 self . variables
45104555 . insert ( format ! ( "_NAMEREF_{}" , var_name) , value. to_string ( ) ) ;
45114556 } else {
@@ -7136,6 +7181,17 @@ impl Interpreter {
71367181 } else {
71377182 result. push_str ( & expanded) ;
71387183 }
7184+ } else if let Some ( & c) = chars. peek ( )
7185+ && matches ! ( c, '#' | '?' | '$' | '!' | '@' | '*' | '-' )
7186+ {
7187+ // Handle special variables: $#, $?, $$, $!, $@, $*, $-
7188+ chars. next ( ) ;
7189+ let value = self . expand_variable ( & c. to_string ( ) ) ;
7190+ if value. is_empty ( ) {
7191+ result. push ( '0' ) ;
7192+ } else {
7193+ result. push_str ( & value) ;
7194+ }
71397195 } else {
71407196 // Handle $var syntax (common in arithmetic)
71417197 let mut name = String :: new ( ) ;
0 commit comments