why can't $module be used as a variable name? in jq

53 Views Asked by At

Is this behaviour of jq, w.r.t the non-allowed use of $module as a variable name, specified anywhere?

$ jq -n --arg 'module' 'X' '$module'
jq: error: syntax error, unexpected module, expecting IDENT or __loc__ (Unix shell quoting issues?) at <top-level>, line 1:
$module 
jq: 1 compile error

My expectation is that jq would print "X", but this is not the case. Why?

1

There are 1 best solutions below

1
peak On

In jq 1.6 and earlier, keywords cannot be used in $-variable names. This is mentioned on the the jq wiki, where the following list of keywords is given:

__loc__ and as break catch def elif else end 
foreach if import include label module
or reduce then try

The list of keywords for any particular version of jq can be derived from the lexer.l file, the “master” version of which is https://github.com/stedolan/jq/blob/master/src/lexer.l

——

The restriction was removed in the development version of jq in 2019 by https://github.com/jqlang/jq/commit/c72ed135e4f1b5a02a8fb3f6cd46f27513ecab2a and thus will no longer exist in jq 1.7