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.14k stars 338 forks source link

Error: parameter expansion requires a literal Info #854

Closed laurentsimon closed 2 years ago

laurentsimon commented 2 years ago

This file https://github.com/flutter/engine/blob/main/tools/fuchsia/devshell/lib/vars.sh#L8 triggers an error parameter expansion requires a literal Info

mvdan commented 2 years ago

Is that valid Bash? I don't think it is, at least from what I can see:

$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ bash -c 'echo ${${(%):-%x}:a:h}'
bash: line 1: ${${(%):-%x}:a:h}: bad substitution
laurentsimon commented 2 years ago

Good point. @godofredoc any comment?

godofredoc commented 2 years ago

It is valid zsh returning the current directory. This is the result from running with zsh:

macbook$ zsh -c 'echo ${${(%):-%x}:a:h}'
/private/tmp
macbook$ 
mvdan commented 2 years ago

Right, though that file has a bash shebang, not a zsh one. This parser does not yet support zsh - see #120.

laurentsimon commented 2 years ago

Thanks, makes sense. Feel free to close the issue. Thank you so much for such a prompt reply

mvdan commented 2 years ago

I'm going to close this in favor of #120, then. I do sort of get why https://github.com/flutter/engine/blob/main/tools/fuchsia/devshell/lib/vars.sh uses bash in its shebang - the script is mostly bash. But the one line that isn't bash still makes the shebang misleading :) It works with bash because it only parses lines when it needs to execute them, but other tools like shfmt or IDEs will often parse all source code upfront, leading to problems like this one.