From f1c627ba32a0485386297d69a60598adb0be66aa Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:27:25 +0800 Subject: [PATCH 1/2] basename: support -- option terminator * Similar to what was committed for bin/dirname, '--' should be interpreted as the end of options (currently it is taken literally) * This was found when testing against OpenBSD version * test1: "perl basename --" --> error, no argument * test2: "perl basename -x" --> error, bad option * test3: "perl basename -- -x" --> basename of "-x" --- bin/basename | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bin/basename b/bin/basename index 746d7ece..b37831a7 100755 --- a/bin/basename +++ b/bin/basename @@ -13,19 +13,15 @@ License: perl use strict; -use File::Basename; -my ($VERSION) = '1.3'; +use File::Basename qw(basename fileparse); +use Getopt::Std qw(getopts); -unless (@ARGV == 1 || @ARGV == 2) { - $0 = basename ($0); - print < "a" my @parsed = fileparse($path); my $name = shift @parsed; print $name, "\n"; +exit 0; + +sub VERSION_MESSAGE { + print "$Program version $VERSION\n"; + exit 0; +} + +sub usage { + warn "usage: $Program string [suffix | /pattern/]\n"; + exit 1; +} __END__ From 24e285e9381edbfeab5bab4e2fda2f20acbfce6d Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:29:10 +0800 Subject: [PATCH 2/2] missed call to usage() --- bin/dirname | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dirname b/bin/dirname index 9e584d3f..b9d24e83 100755 --- a/bin/dirname +++ b/bin/dirname @@ -21,7 +21,7 @@ use Getopt::Std qw(getopts); my $Program = basename($0); our $VERSION = '1.3'; -getopts('') or die "usage: $Program string\n"; +getopts('') or usage(); usage() unless scalar(@ARGV) == 1; my $path = shift; my $dir = dirname($path);