Open verhovsky opened 3 years ago
This may be a similar issue, or my own misunderstanding of bashlex:
>>> bashlex.parse('DOCKER_BUILDTAGS+=" $tag"')
[CommandNode(parts=[AssignmentNode(parts=[ParameterNode(pos=(20, 24) value='tag')] pos=(0, 25) word='DOCKER_BUILDTAGS+= $tag')] pos=(0, 25))]
I expected the following output instead:
[CommandNode(parts=[AssignmentNode(parts=[ParameterNode(pos=(20, 24) value='tag')] pos=(0, 25) word='DOCKER_BUILDTAGS+=" $tag"')] pos=(0, 25))]
@d4g33z that is unrelated to this issue and bashlex lexes your example correctly. This is how bash interprets that:
$ tag="world"
$ echo hello=" $tag"
hello= world
$
In other words, echo
gets one argument with $tag
substituted for the value of the tag
variable and the quotes removed. The "
quotes are needed so that you can have whitespace in one argument (otherwise echo hello= $tag
would pass two arguments to echo
: hello=
and $tag
, which it would print separated by 1 space instead of however many I put in there, and that's just because of how echo
works, it prints arguments separated by a space), they are stripped by bash before passing the args to the command being called.
Sorry to hijack the issue. I'll have to revisit parsing += assignments that concatenate strings with white space.
Thanks, it's a great library.
https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Expected result:
Actual result (
bashlex
0.15):