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
7.1k stars 336 forks source link

shfmt removes ; from find -exec #916

Closed gunnihinn closed 1 year ago

gunnihinn commented 1 year ago

The find command manual says about one of its options:

-exec command ;
  Execute command; true if 0 status is returned. All following arguments to find are
  taken to be arguments to the command until an argument consisting of `;' is encountered.

However, shfmt shortens

find . -name "*" -exec echo {} ;

to

find . -name "*" -exec echo {}

resulting in the error find: missing argument to '-exec'. A workaround is to quote the ;

find . -name "*" -exec echo {} ';'

but is this something the tool should be aware of?

mvdan commented 1 year ago

From man find, note that all the exampes use an escaped semicolon:

$ find . -type f -exec file '{}' \;

I'm pretty sure that works fine with shfmt, as does ';'. The lack of escaping or quoting would break find, I'm pretty sure - because then the semicolon is not part of the argument list.

gunnihinn commented 1 year ago

That makes sense, I'm not sure how I missed that. I could swear I was running that command with an unquoted ; before. Sorry for the noise.

PS. I love shfmt so much. Thank you!