5
pam_getenv - get environment variables from /etc/environment
9
pam_getenv B<[-l] [-s]> I<env_var>
13
This tool will print out the value of I<env_var> from F</etc/environment>. It will attempt to expand environment variable references in the definition of I<env_var> but will fail if PAM items are expanded.
15
The B<-l> option indicates the script should return an environment variable related to default locale information.
17
The B<-s> option indicates that the script should return an
18
system default environment variable.
20
Currently neither the B<-l> or B<-s> options do anything. They are
21
included because future versions of Debian may have a separate
22
repository for the initial environment used by init scripts and for
23
system locale information. These options will allow this script to be
24
a stable interface even in that environment.
28
# Copyright 2004 by Sam Hartman
29
# This script may be copied under the terms of the GNU GPL
30
# version 2, or at your option any later version.
33
use vars qw(*ENVFILE);
38
line: while (<ENVFILE>) {
60
return undef unless defined $_ and s/(\S+)\s//;
63
@x = split(/=([^"\s]\S*|"[^"]*")\s*/, $_);
64
unless (scalar(@x)%2 == 0) {
68
@{$var}{"Default", "Override"} =
69
@x{"DEFAULT", "OVERRIDE"};
75
return undef unless $val;
76
die "Cannot handle PAM items\n" if /(?<!\\)\@/;
77
$val =~ s/(?<!\\)\${([^}]+)}/$ENV{$1}||""/eg;
83
open (ENVFILE, "/etc/environment")
84
or die "Cannot open environment file: $!\n";
90
variable: while ($var = parse_line(read_line())) {
92
next variable unless $var->{Name} eq $_;
93
unless ($val = expand_val($var->{Override})) {
94
$val = expand_val($var->{Default});