Parse command-line arguments: Difference between revisions

(Added XPL0 example.)
Line 378:
Other concepts are also possible...
 
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
 
The jq and gojq programs parse some command-line options and arguments for their own purposes
but also provide two mechanisms allowing for arbitrarily many command-line arguments to be provided to the program:
 
* the --args option can be used to provide a sequence of shell strings that are converted to JSON strings;
* the --jsonargs option can similarly be used to specify a sequence of JSON values.
 
For example, assuming a bash or bash-like shell, the invocation
<pre>
jq -n '$ARGS' --args 1 two '[3, "four"]'
</pre>
results in:
<pre>
{
"positional": [
"1",
"two",
"[3, \"four\"]"
],
"named": {}
}
</pre>
whereas:
<pre>
jq -n '$ARGS' --jsonargs 1 '"two"' '[3, "four"]'
</pre>
results in:
<pre>
{
"positional": [
1,
"two",
[
3,
"four"
]
],
"named": {}
}
</pre>
 
Notice that in the first case, the token `two` has not been quoted, whereas in the second case, it must be presented as `'"two"'`
if it is to be understood as a JSON string.
=={{header|Julia}}==
{{works with|Julia|0.6}}
2,455

edits