Skip to content

Commit

Permalink
printenv: retire -? flag (#503)
Browse files Browse the repository at this point in the history
* Remove -? which is not present in GNU or BSD version of printenv
* The BSD version does not support options starting with a dash
* While here, restructure code to avoid multiple exits; exit code 1 is designated for the (optional) argument not being found in environment
  • Loading branch information
mknos committed Mar 14, 2024
1 parent f85948f commit 099cbdb
Showing 1 changed file with 13 additions and 32 deletions.
45 changes: 13 additions & 32 deletions bin/printenv
Expand Up @@ -14,29 +14,22 @@ License: perl

use strict;

my ($VERSION) = '1.2';

if (@ARGV) {
if ($ARGV[0] eq '-?') {
$0 =~ s{.*/}{};
print <<EOF;
Usage: $0 [name]
Display the environment. If an argument is given, only the value
of that variable is displayed.
EOF
exit;
} elsif (exists $ENV{$ARGV[0]}) {
print $ENV{$ARGV[0]}, "\n";
exit;
my ($VERSION) = '1.3';

my $rc = 0;
my $arg = shift;
if (defined $arg) {
if (exists $ENV{$arg}) {
print $ENV{$arg}, "\n";
} else {
exit 1;
$rc = 1;
}
} else {
while (my ($key, $value) = each(%ENV)) {
print "$key=$value\n";
}
}

while (my ($key, $value) = each(%ENV)) { print "$key=$value\n"; }
exit;
exit $rc;

__END__
Expand All @@ -55,18 +48,6 @@ printenv [name]
printenv displays the current environment. If an argument is supplied, only the
value of that variable is displayed.
=head2 OPTIONS
I<printenv> accepts the following options:
=over 4
=item -?
Print out a short help message, then exit.
=back
=head1 BUGS
I<printenv> has no known bugs.
Expand Down

0 comments on commit 099cbdb

Please sign in to comment.