1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
3 // Copyright (c) 2001-2003, OpenBeOS
5 // This software is part of the OpenBeOS distribution and is covered
10 // Author: Daniel Reinhold (danielre@users.sf.net)
11 // Description: prints environment variables
13 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
21 extern char **environ
;
23 int print_env(char *);
27 main(int argc
, char *argv
[])
29 char *arg
= (argc
== 2 ? argv
[1] : NULL
);
31 if ((argc
> 2) || (arg
&& !strcmp(arg
, "--help"))) {
32 printf("Usage: printenv [VARIABLE]\n"
33 "If no environment VARIABLE is specified, print them all.\n");
37 return print_env(arg
);
47 // print all environment 'key=value' pairs (one per line)
49 printf("%s\n", *env
++);
53 // print only the value of the specified variable
55 int len
= strlen(arg
);
58 while ((s
= *env
++) != NULL
)
59 if (!strncmp(s
, arg
, len
)) {
60 char *p
= strchr(s
, '=');
67 return (found
? 0 : 1);