From 742ff5161874a585a8c612ca3912a806d243db0e Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Wed, 3 Jan 2024 22:38:36 +0800 Subject: [PATCH] tail: allow -n1 and -n 1 * I habitually type "tail -n5"; this is supported by GNU tail and OpenBSD tail * Enabling bundling option in Getopt::Long makes it work in this version * Style: avoid capture variable when the entire argument string "+590" is passed to check_number() * test1: "perl tail -5 tail" -- historical option format, last 5 lines * test2: "perl tail +590 tail" -- historical option format, line 590 to end * test3: "perl tail -n5 tail" -- last 5 lines * test4: "perl tail -n-5 tail" -- last 5 lines * test5: "perl tail -n+590 tail" -- line 590 to end --- bin/tail | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/tail b/bin/tail index 6318caec..8e0b357c 100755 --- a/bin/tail +++ b/bin/tail @@ -82,8 +82,8 @@ sub parse_args() } else { - # special handling for -numeric options - Getopt::Long::config("pass_through"); + # pass_through is special handling for -numeric options + Getopt::Long::config('bundling', 'pass_through'); GetOptions("b=s", "c=s", "f", "h", "n=s", "r"); usage 0 if $opt_h; @@ -104,8 +104,11 @@ sub parse_args() } for (@ARGV) { - $point = check_number($1), shift @ARGV, last - if /^([-+].*)$/; + if (m/\A[\-\+]/) { + $point = check_number($_); + shift @ARGV; + last; + } } usage 1, "The number cannot be null" if $point == 0;