From e0a74bbef56bf3449664fd21852f918c042e3214 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:28:24 +0800 Subject: [PATCH] chmod: show which option is wrong * The supported options are -R/-L/-H/-P, and grouping of options is allowed (e.g. -LP) * When adding an unexpected option letter to a group, the error message was misleading * "perl chmod -Rp" reported "invalid option -- pR", but R is a valid option * Fix this by validation the option letters after the option string has been split into a single letters --- bin/chmod | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/chmod b/bin/chmod index 7a5e60de..ce970bce 100755 --- a/bin/chmod +++ b/bin/chmod @@ -30,12 +30,12 @@ while (@ARGV && $ARGV [0] =~ /^-/) { my $opt = reverse shift; chop $opt; last if ($opt eq '-'); - unless ($opt =~ /^[RHLP]+$/) { - warn "$Program: invalid option -- $opt\n"; - usage(); - } local $_; while (length ($_ = chop $opt)) { + unless (m/\A[RHLP]\Z/) { + warn "$Program: invalid option -- '$_'\n"; + usage(); + } /R/ && do {$options {R} = 1; next}; usage() unless $options{'R'}; /H/ && do {$options {L} = $options {P} = 0; $options {H} = 1; next};