Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env: validate -u argument #266

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/env
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ while ( @ARGV && $ARGV[0] =~ /^-/ ) {
if ( $arg eq '-i' ) {
%ENV = ();
} elsif ( $arg =~ /^-u(.*)/ ) {
delete $ENV{ length($1) ? $1 : shift };
my $val = length $1 ? $1 : shift;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit ugly, but until we switch to Get::Opts, this is fine. I've done it like this before but I've never been happy with it.

if ($val =~ m/=/) {
warn "$Program: bad unset argument: '$val'\n";
exit 2;
}
delete $ENV{$val};
} else {
warn "$Program: invalid option -- $arg\n";
exit 2;
Expand Down Expand Up @@ -85,6 +90,7 @@ Clears the environment, passing only the values specifed to the command.
=item B<-u> I<name>

Clears the environment variable I<name> if it exists.
The value must not include the '=' character.

=back

Expand Down