docs: rename example jq utility to total
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Apparently sum(1) is a BSD and GNU coreutil used to compute the "16-bit BSD checksum" of a file.
authored by Emanuele Torre · committed by Nico Williams · parent bd3c828 · Browse files · 2 files·+11 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+11 added−11 removed
- other:+11 added−11 removed
Provenance
- Commit
13e02ba- Tree
1463894- Author
Emanuele Torre <torreemanuele6@gmail.com>- Committer
Nico Williams <nico@cryptonector.com>- Parent
bd3c828
2 files changed+11 added−11 removed
modified:docs/content/manual/manual.yml+6 added-6 removed
3569 unmodified lines3570 Backslash continuing the comment on the next line can be useful3571 when writing the "shebang" for a jq script:3572 3573 #!/bin/sh --3574- # sum - Output the sum of the given arguments (or stdin)3575- # usage: sum [numbers...]3574+ # total - Output the sum of the given arguments (or stdin)3575+ # usage: total [numbers...]3576 # \3577 exec jq --args -MRnf "$0" -- "$@"3578 3579 $ARGS.positional |4 unmodified lines3584 end |3585 . as $dot |3586 try tonumber catch false |3587 if not or isnan then3588- @json "sum: Invalid number \($dot).\n" | halt_error(1)3588+ @json "total: Invalid number \($dot).\n" | halt_error(1)3589 end3590 ) as $n (0; . + $n)3591 3592 The `exec` line is considered a comment by jq, so it is ignored.3593 But it is not ignored by `sh`, since in `sh` a backslash at the3594 end of the line does not continue the comment.3595- With this trick, when the script is invoked as `sum 1 2`,3596- `/bin/sh -- /path/to/sum 1 2` will be run, and `sh` will then3597- run `exec jq --args -MRnf /path/to/sum -- 1 2` replacing itself3595+ With this trick, when the script is invoked as `total 1 2`,3596+ `/bin/sh -- /path/to/total 1 2` will be run, and `sh` will then3597+ run `exec jq --args -MRnf /path/to/total -- 1 2` replacing itself3598 with a `jq` interpreter invoked with the specified options (`-M`,3599 `-R`, `-n`, `--args`), that evaluates the current file (`$0`),3600 with the arguments (`$@`) that were passed to `sh`.3601 162 unmodified linesmodified:jq.1.prebuilt+5 added-5 removed
1 .2-.TH "JQ" "1" "December 2023" "" ""2+.TH "JQ" "1" "January 2024" "" ""3 .4 .SH "NAME"5 \fBjq\fR \- Command\-line JSON processor6 .3990 unmodified lines3997 .3998 .nf3999 4000 #!/bin/sh \-\-4001-# sum \- Output the sum of the given arguments (or stdin)4002-# usage: sum [numbers\.\.\.]4001+# total \- Output the sum of the given arguments (or stdin)4002+# usage: total [numbers\.\.\.]4003 # \e4004 exec jq \-\-args \-MRnf "$0" \-\- "$@"4005 4006 $ARGS\.positional |4 unmodified lines4011 end |4012 \. as $dot |4013 try tonumber catch false |4014 if not or isnan then4015- @json "sum: Invalid number \e($dot)\.\en" | halt_error(1)4015+ @json "total: Invalid number \e($dot)\.\en" | halt_error(1)4016 end4017 ) as $n (0; \. + $n)4018 .4019 .fi4020 .4021 .IP "" 04022 .4023 .P4024-The \fBexec\fR line is considered a comment by jq, so it is ignored\. But it is not ignored by \fBsh\fR, since in \fBsh\fR a backslash at the end of the line does not continue the comment\. With this trick, when the script is invoked as \fBsum 1 2\fR, \fB/bin/sh \-\- /path/to/sum 1 2\fR will be run, and \fBsh\fR will then run \fBexec jq \-\-args \-MRnf /path/to/sum \-\- 1 2\fR replacing itself with a \fBjq\fR interpreter invoked with the specified options (\fB\-M\fR, \fB\-R\fR, \fB\-n\fR, \fB\-\-args\fR), that evaluates the current file (\fB$0\fR), with the arguments (\fB$@\fR) that were passed to \fBsh\fR\.4024+The \fBexec\fR line is considered a comment by jq, so it is ignored\. But it is not ignored by \fBsh\fR, since in \fBsh\fR a backslash at the end of the line does not continue the comment\. With this trick, when the script is invoked as \fBtotal 1 2\fR, \fB/bin/sh \-\- /path/to/total 1 2\fR will be run, and \fBsh\fR will then run \fBexec jq \-\-args \-MRnf /path/to/total \-\- 1 2\fR replacing itself with a \fBjq\fR interpreter invoked with the specified options (\fB\-M\fR, \fB\-R\fR, \fB\-n\fR, \fB\-\-args\fR), that evaluates the current file (\fB$0\fR), with the arguments (\fB$@\fR) that were passed to \fBsh\fR\.4025 .4026 .SH "MODULES"4027 jq has a library/module system\. Modules are files whose names end in \fB\.jq\fR\.4028 .171 unmodified lines