From a52713839d4ee33a8136ef4064aa5b190b6ff895 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Wed, 31 Jan 2024 06:40:12 +0800 Subject: [PATCH] sleep: fail for extra args (#430) * Align sleep with OpenBSD version, which shows usage string if extra arguments are given * Previously this version ignored extra arguments * Make pod text more useful * test1: "perl sleep" --> no argument * test2: "perl sleep -x" --> bad option * test3: "perl sleep -- 1" --> valid: supported by GNU and OpenBSD * test4: "perl sleep -- -1" --> bad interval * test5: "perl sleep -- 1 2" --> too many arguments --- bin/sleep | 62 +++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/bin/sleep b/bin/sleep index 33a4a21b..20a44d90 100755 --- a/bin/sleep +++ b/bin/sleep @@ -13,31 +13,36 @@ License: perl use strict; -my ($VERSION) = '1.202'; +use File::Basename qw(basename); +use Getopt::Std qw(getopts); +use constant EX_SUCCESS => 0; +use constant EX_FAILURE => 1; + +my $Program = basename($0); +my ($VERSION) = '1.203'; + +getopts('') or usage(); +my $seconds = shift; +unless (defined $seconds) { + warn "$Program: missing operand\n"; + usage(); +} if (@ARGV) { - if ($ARGV [0] eq '-?') { - $0 =~ s{.*/}{}; - print < =head1 DESCRIPTION -I exits succesfully. I exits unsuccesfully. - -=head2 OPTIONS - -I accepts the following options: - -=over 4 - -=item -? - -Print out a short help message, then exit. - -=back +I waits for a number of seconds, then exits successfully. +The argument is taken as a decimal number with no fractional part. =head1 ENVIRONMENT