2024-02-02 03:40:50 +00:00
|
|
|
|
.\" Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
2024-03-27 00:26:51 +00:00
|
|
|
|
.\" Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
2023-12-25 00:13:17 +00:00
|
|
|
|
.\"
|
|
|
|
|
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
|
|
|
|
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
|
|
|
|
|
|
|
|
|
.TH intcmp 1
|
|
|
|
|
|
|
|
|
|
.SH NAME
|
|
|
|
|
|
|
|
|
|
intcmp \(en compare integers
|
|
|
|
|
|
|
|
|
|
.SH SYNOPSIS
|
|
|
|
|
|
|
|
|
|
intcmp
|
2024-03-27 00:26:51 +00:00
|
|
|
|
.RB ( -egl )
|
2023-12-25 00:13:17 +00:00
|
|
|
|
.RB [ integer ]
|
|
|
|
|
.RB [ integer... ]
|
|
|
|
|
|
|
|
|
|
.SH DESCRIPTION
|
|
|
|
|
|
2024-03-29 22:22:56 +00:00
|
|
|
|
Compare integers to each other.
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
|
|
|
|
.SH USAGE
|
|
|
|
|
|
2024-03-27 00:26:51 +00:00
|
|
|
|
.B -e
|
|
|
|
|
.RS
|
|
|
|
|
Permits given integers to be equal to each other. If combined with
|
|
|
|
|
.B -g
|
|
|
|
|
or
|
|
|
|
|
.B -l
|
|
|
|
|
, only adjacent integers in the argument sequence can be equal.
|
|
|
|
|
.RE
|
|
|
|
|
|
|
|
|
|
.B -g
|
|
|
|
|
.RS
|
|
|
|
|
Permits a given integer to be greater than the following integer.
|
|
|
|
|
.RE
|
|
|
|
|
|
|
|
|
|
.B -l
|
|
|
|
|
.RS
|
|
|
|
|
Permits a given integer to be less than the following integer.
|
|
|
|
|
.RE
|
|
|
|
|
|
|
|
|
|
.SH EXAMPLES
|
|
|
|
|
|
2023-12-25 00:13:17 +00:00
|
|
|
|
It may help to think of the -e, -g, and -l options as equivalent to the
|
|
|
|
|
infix algebraic “=”, “>”, and “<” operators respectively, with each option
|
2024-03-27 00:26:51 +00:00
|
|
|
|
putting its symbol between every given integer. The following example is
|
|
|
|
|
equivalent to evaluating “1 < 2 < 3”:
|
|
|
|
|
|
|
|
|
|
.RS
|
2023-12-25 00:13:17 +00:00
|
|
|
|
.R intcmp -l 1 2 3
|
2024-03-27 00:26:51 +00:00
|
|
|
|
.RE
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
|
|
|
|
.SH DIAGNOSTICS
|
|
|
|
|
|
2024-03-27 01:22:30 +00:00
|
|
|
|
The program will exit with a status code of 0 for a valid expression and with a
|
|
|
|
|
code of 1 for an invalid expression.
|
2024-03-27 00:26:51 +00:00
|
|
|
|
|
2024-03-27 01:22:30 +00:00
|
|
|
|
In the event of an error, a debug message will be printed and the program will
|
|
|
|
|
exit with the appropriate sysexits.h(3) error code.
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
|
|
|
|
.SH BUGS
|
|
|
|
|
|
|
|
|
|
There are multiple ways to express compound comparisons; “less than or equal
|
|
|
|
|
to” can be -le or -el, for example.
|
2024-03-27 00:26:51 +00:00
|
|
|
|
|
2023-12-25 00:13:17 +00:00
|
|
|
|
The inequality comparison is -gl or -lg for “less than or greater than”; this
|
|
|
|
|
is elegant but unintuitive.
|
2024-03-27 00:26:51 +00:00
|
|
|
|
|
|
|
|
|
-egl, “equal to or less than or greater than”, exits 0 no matter what for valid
|
2023-12-25 00:13:17 +00:00
|
|
|
|
program usage and may be abused to function as an integer validator.
|
|
|
|
|
Use str(1) instead.
|
|
|
|
|
|
|
|
|
|
.SH RATIONALE
|
|
|
|
|
|
|
|
|
|
The traditional tool for integer comparisons in POSIX and other Unix shells has
|
|
|
|
|
been test(1). This tool also handles string comparisons and file scrutiny.
|
|
|
|
|
These parts of its functionality have been broken out into multiple utilities.
|
|
|
|
|
|
2024-03-27 01:22:30 +00:00
|
|
|
|
This program’s functionality may be performed on a POSIX-compliant system with
|
2023-12-25 00:13:17 +00:00
|
|
|
|
test(1p).
|
|
|
|
|
|
|
|
|
|
.SH AUTHOR
|
|
|
|
|
|
|
|
|
|
Written by DTB <trinity@trinity.moe>.
|
|
|
|
|
|
|
|
|
|
.SH COPYRIGHT
|
|
|
|
|
|
|
|
|
|
Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
|
|
|
|
<https://gnu.org/licenses/gpl.html>.
|
|
|
|
|
|
|
|
|
|
.SH SEE ALSO
|
|
|
|
|
|
2024-02-02 03:40:50 +00:00
|
|
|
|
strcmp(1), scrut(1), str(1), test(1p)
|