env | grep PATH | lenv -e'
Options:
-e | Expect 'env' command output as standard input | |
-h | Help |
This example shows the values of the $CLASSPATH and $PATH environment variables.
An example of using lenv:
$ lenv CLASSPATH PATH CLASSPATH = /usr/local/inst/jConnect-5_2/classes/jconn2.jar : /usr/local/inst/jdk1.2.2/lib/tools.jar : /home/httpd/classes/servlet-2.0.jar : /usr/local/inst/ant-1.2-1/share/java/ant.jar : /usr/local/inst/ant-1.2-1/share/java/jaxp.jar : /usr/local/inst/ant-1.2-1/share/java/parser.jar : /home/alan/work/crs/web/src PATH = /opt/sybase-11.9.2/bin : /usr/local/inst/jdk1.2.2/bin : /usr/local/bin : /bin : /usr/bin : /usr/X11R6/bin : /usr/local/bin : /home/alan/bin : /home/alan/local/bin : /usr/local/inst/jdk1.2.2/bin : /usr/local/inst/ant-1.2-1/bin
#!/usr/bin/perl
#
# 11.10.96 ah
require "getopts.pl";
# =============================================================================
sub Usage {
print STDERR <<EndOfUsage;
Usage: $0 [-eh] [variable names..]
-h for help
EndOfUsage
}
sub Help {
print STDERR <<EndOfHelp;
Usage: $0 [options] [variable names..]
Description:
List environment variables in 'human readable' format. If the '-e'
option is given then the program expects the output of the 'env'
command as its input (E.g. 'env | grep PATH | lenv -e').
Options:
-e Expect 'env' command output as standard input
-h Help
EndOfHelp
exit (1);
}
# =============================================================================
&Getopts ('eh');
defined ($opt_h) && &Help;
if (!defined ($opt_e)) {
%VARS = %ENV;
} else {
# ---- generate the %VARS array from stdin and/or names files
while (<>) {
$line = $_;
chop ($line);
$var = $line;
$var =~ s/=.*//;
$value = substr ($line, length ($var) + 1);
$VARS { $var } = $value;
}
}
# ----- Set up an associative array with the requested variable=value pairs
# if there are left over arguments
if (scalar (@ARGV) > 0) {
%VARS = ();
foreach $var (@ARGV) {
$VARS { $var } = $ENV { $var };
}
}
# ----- Get the maximum variable length
$mlen = 0;
foreach $key (sort (keys %VARS)) {
$mlen = length ($key) if (length ($key) > $mlen)
}
# ----- Output the report
$blank = ' ';
$pad = substr ($blank, 0, $mlen + 1);
foreach $key (sort (keys %VARS)) {
$value = $VARS { $key };
if ($mlen + length ($value) > 80 || $key =~ /PATH$/) {
# ----- make paths and long items into vertical list
$value =~ s/\s+/\n${pad} /g;
$value =~ s/:/\n${pad}: /g;
}
printf ("%s%s = %s\n",
$key,
substr ($blank, 0, $mlen - length($key)),
$value);
}
# ----- end