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

syntax: confusing error when "function" is used in posix mode #911

Closed wangyushui closed 1 year ago

wangyushui commented 1 year ago
mvdan commented 1 year ago

I think you want to be using #!/bin/bash as your shebang, as function is a Bash feature. Or otherwise, explicitly pass in the -ln=bash flag. Although our error message here could probably be more helpful, so I think it's worth keeping this issue open for that improvement.

wangyushui commented 1 year ago

Thank you for your reply. I agree with you

I think you want to be using #!/bin/bash as your shebang, as function is a Bash feature. Or otherwise, explicitly pass in the -ln=bash flag. Although our error message here could probably be more helpful, so I think it's worth keeping this issue open for that improvement.

mvdan commented 1 year ago

I'll keep this open for the sake of better errors :)