Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: regression in parsing of "declare" #129

Closed
cyphar opened this issue Jul 3, 2017 · 5 comments
Closed

syntax: regression in parsing of "declare" #129

cyphar opened this issue Jul 3, 2017 · 5 comments
Labels
Milestone

Comments

@cyphar
Copy link

cyphar commented Jul 3, 2017

We just hit this in runc in the past few days. If you run shfmt on something like this:

export completion_func=_some_func_name
declare -F $completion_func

You get this error even though it is entirely valid bash.

2:12: "declare" must be followed by names or assignments
@mvdan
Copy link
Owner

mvdan commented Jul 3, 2017

Thanks! Will look into it.

@mvdan mvdan added this to the 2.0 milestone Jul 3, 2017
@mvdan mvdan added the bug label Jul 3, 2017
@mvdan mvdan changed the title regression: incorrect error with declare syntax: regression in parsing of "declare" Jul 3, 2017
@mvdan
Copy link
Owner

mvdan commented Jul 3, 2017

@cyphar just to confirm, you only use declare ... $var in the context where $var only holds a name like foo, correct? You wouldn't do it where var='foo[0]' or var='foo=bar', hopefully?

@cyphar
Copy link
Author

cyphar commented Jul 3, 2017

declare -F $var is only valid if $var is a name. However, note that declare $var is valid if var="a=b". For example:

$ export var="a=b"
$ declare $var
$ echo $a
b

We're not using the latter, but you should be aware that is a valid bash-ism. declare k[0] is also valid.

@mvdan
Copy link
Owner

mvdan commented Jul 3, 2017

I ran the same tests - that's why I'm asking. I think I'll just allow this assuming that $var just contains a name no matter what, as otherwise this would be a rabbit hole.

@mvdan mvdan closed this as completed in c2b7a22 Jul 3, 2017
@cyphar
Copy link
Author

cyphar commented Jul 3, 2017

Thanks for the incredibly fast turnaround @mvdan. 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants