Skip to content

Commit

Permalink
docs: rename example jq utility to total
Browse files Browse the repository at this point in the history
Apparently sum(1) is a BSD and GNU coreutil used to compute the
"16-bit BSD checksum" of a file.
  • Loading branch information
emanuele6 authored and nicowilliams committed Jan 30, 2024
1 parent bd3c828 commit 13e02ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3571,8 +3571,8 @@ sections:
when writing the "shebang" for a jq script:
#!/bin/sh --
# sum - Output the sum of the given arguments (or stdin)
# usage: sum [numbers...]
# total - Output the sum of the given arguments (or stdin)
# usage: total [numbers...]
# \
exec jq --args -MRnf "$0" -- "$@"
Expand All @@ -3585,16 +3585,16 @@ sections:
. as $dot |
try tonumber catch false |
if not or isnan then
@json "sum: Invalid number \($dot).\n" | halt_error(1)
@json "total: Invalid number \($dot).\n" | halt_error(1)
end
) as $n (0; . + $n)
The `exec` line is considered a comment by jq, so it is ignored.
But it is not ignored by `sh`, since in `sh` a backslash at the
end of the line does not continue the comment.
With this trick, when the script is invoked as `sum 1 2`,
`/bin/sh -- /path/to/sum 1 2` will be run, and `sh` will then
run `exec jq --args -MRnf /path/to/sum -- 1 2` replacing itself
With this trick, when the script is invoked as `total 1 2`,
`/bin/sh -- /path/to/total 1 2` will be run, and `sh` will then
run `exec jq --args -MRnf /path/to/total -- 1 2` replacing itself
with a `jq` interpreter invoked with the specified options (`-M`,
`-R`, `-n`, `--args`), that evaluates the current file (`$0`),
with the arguments (`$@`) that were passed to `sh`.
Expand Down
10 changes: 5 additions & 5 deletions jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 13e02ba

Please sign in to comment.