joerdav / xc

Markdown defined task runner.
https://xcfile.dev/
MIT License
1.17k stars 27 forks source link

Associative array support #115

Closed 1buran closed 6 months ago

1buran commented 6 months ago

Hello!

Does the tool support associative arrays?

I tried to define a task with arrays something like this one:

declare -A demo                       
demo["main"]="Main demo"              
demo["json-min"]="JSON min"           
demo["load-session"]="Load session"   

for i in ${!demo[@]}; do              
    echo "$i-> ${demo[$i]}"            
done                                  

output of xc:

imgur| + demo='Main demo'
imgur| + demo='JSON min'
imgur| + demo='Load session'
imgur| + for i in ${!demo[@]}
imgur| + echo '0 -> Load session'
imgur| 0 -> Load session
joerdav commented 6 months ago

The interpreter I use is https://github.com/mvdan/sh

Which should support this... I'll investigate.

joerdav commented 6 months ago

I managed to get your example working with the following:

declare -A demo=()                       
demo["main"]="Main demo"              
demo["json-min"]="JSON min"           
demo["load-session"]="Load session"   

for i in ${!demo[@]}; do              
    echo "$i-> ${demo[$i]}"            
done      

If that isn't sufficient then I recommend raising an issue on: https://github.com/mvdan/sh

1buran commented 5 months ago

So my mistake was in the array declaration, got it, now it works, thanks!

joerdav commented 5 months ago

Great! Thanks for reporting back!