mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.99k stars 333 forks source link

Notes from Bash 5.2 changelog #921

Open mvdan opened 1 year ago

mvdan commented 1 year ago

See https://lwn.net/Articles/909596/. Quoting below the bits that may require changes in our parser.

e. Here-document parsing now handles $'...' and $"..." quoting when reading the
   here-document body.

l. The `unset' builtin allows a subscript of `@' or `*' to unset a key with
   that value for associative arrays instead of unsetting the entire array
   (which you can still do with `unset arrayname'). For indexed arrays, it
   removes all elements of the array without unsetting it (like `A=()').

t. There is a new parameter transformation operator: @k. This is like @K, but
   expands the result to separate words after word splitting.

w. Invalid parameter transformation operators are now invalid word expansions,
   and so cause fatal errors in non-interactive shells.
ConnorBaker commented 1 month ago

@mvdan in terms of adding support for @k, do you have an idea of the amount of work required? Would it be as simple as adding it to https://github.com/mvdan/sh/blob/23633a432f903599a4ce46c30c4337e413a26ef1/syntax/parser.go#L1378?

I ask because I'm getting errors trying to format a bash script using @k.

mvdan commented 1 month ago

@ConnorBaker as far as the parser, yes, that should be it - plus a test. I'll send a patch shortly given this is so trivial.