Command-line arguments: Difference between revisions
jq
(jq) |
|||
Line 812:
<lang javascript>for (var i = 0; i < arguments.length; i++)
print(arguments[i]);</lang>
=={{header|jq}}==
{{works with|jq|after February 17, 2017}}
<br/>
jq distinguishes between command-line arguments and command-line options.
Only the former are available programmatically.
Specifically, both named and positional command-line arguments are available in the
global constant '''$ARGS''', a JSON object, as follows:
$ARGS.positional contains an array of the positional arguments as JSON strings
$ARGS.names is a JSON object of giving the mapping of name to value.
For example, the invocation:
$ jq -n '$ARGS' --args a b
yields:<lang json>{
"positional": [
"a",
"b"
],
"named": {}
}</lang>
Arguments specified with ''--args'' are always read as JSON strings; arguments specified with ''--jsonargs''
are interpreted as JSON, as illustrated here:
<pre>
$ jq -n '$ARGS' --argjson x 0 --jsonargs 0 '{"a":1}'
{
"positional": [
0,
{
"a": 1
}
],
"named": {
"x": 0
}
}</pre>
=={{header|Julia}}==
|