You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Will respond with additional details on Monday when I am back at work but I did figure out to change it to not use the function keyword yesterday and it worked.
I am inheriting some shell scripts I didn't write - thank you for the hint to look at the mode.
@rgowtham as I tried to explain in my previous comment, this is not a bug in shfmt - the parser will work if you properly parse the script as Bash. You can do that explicitly via the -ln=bash flag, or by naming the script foo.bash, or by adding a shebang like #!/usr/bin/bash. Instead of any of those three options, your script probably just has a name like foo.sh, so the parser assumes POSIX shell, where function is not a valid way to declare functions.
Activity
mvdan commentedon Apr 22, 2023
What did you run exactly?. It's likely that you're trying to parse in POSIX mode when this is bash syntax.
leetrout commentedon Apr 22, 2023
I just ran
shfmt <file>Will respond with additional details on Monday when I am back at work but I did figure out to change it to not use the
functionkeyword yesterday and it worked.I am inheriting some shell scripts I didn't write - thank you for the hint to look at the mode.
rgowtham commentedon Jun 22, 2023
I am seeing a similar behavior with the below function as well,
I am using shfmt 3.7.0, not sure why shfmt considers this a bug
mvdan commentedon Jun 23, 2023
@rgowtham as I tried to explain in my previous comment, this is not a bug in shfmt - the parser will work if you properly parse the script as Bash. You can do that explicitly via the
-ln=bashflag, or by naming the scriptfoo.bash, or by adding a shebang like#!/usr/bin/bash. Instead of any of those three options, your script probably just has a name likefoo.sh, so the parser assumes POSIX shell, wherefunctionis not a valid way to declare functions.mvdan commentedon Jul 13, 2023
The parser should now give a better error message.
syntax: better error when using "function" in POSIX mode