bashlex
bashlex copied to clipboard
[request] Add support for local, global, and export
If an assign statement is used after local, global, and export it is treated as a word node, not an assignment node.
Agree. I often will declare functions as:
foo() {
local key="$1"
local value="$2"
# Do the "needful"
}
I was unable to reproduce an issue with local
, global
, or export
using version 0.18.
In a Python interactive session (using bashlex v0.18):
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bashlex
>>> bashlex.parse('local key=1')
[CommandNode(parts=[WordNode(parts=[] pos=(0, 5) word='local'), WordNode(parts=[] pos=(6, 11) word='key=1')] pos=(0, 11))]
>>> bashlex.parse('global key=1')
[CommandNode(parts=[WordNode(parts=[] pos=(0, 6) word='global'), WordNode(parts=[] pos=(7, 12) word='key=1')] pos=(0, 12))]
>>> bashlex.parse('export key=1')
[CommandNode(parts=[WordNode(parts=[] pos=(0, 6) word='export'), WordNode(parts=[] pos=(7, 12) word='key=1')] pos=(0, 12))]