1/* printenv -- minimal clone of BSD printenv(1). 2 3 usage: printenv [varname] 4 5 Chet Ramey 6 chet@po.cwru.edu 7*/ 8 9/* Copyright (C) 1997-2002 Free Software Foundation, Inc. 10 11 This file is part of GNU Bash, the Bourne Again SHell. 12 13 Bash is free software; you can redistribute it and/or modify it under 14 the terms of the GNU General Public License as published by the Free 15 Software Foundation; either version 2, or (at your option) any later 16 version. 17 18 Bash is distributed in the hope that it will be useful, but WITHOUT ANY 19 WARRANTY; without even the implied warranty of MERCHANTABILITY or 20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21 for more details. 22 23 You should have received a copy of the GNU General Public License along 24 with Bash; see the file COPYING. If not, write to the Free Software 25 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 26 27#if defined (HAVE_CONFIG_H) 28# include <config.h> 29#endif 30 31#include "bashansi.h" 32 33extern char **environ; 34 35int 36main (argc, argv) 37 int argc; 38 char **argv; 39{ 40 register char **envp, *eval; 41 int len; 42 43 argv++; 44 argc--; 45 46 /* printenv */ 47 if (argc == 0) 48 { 49 for (envp = environ; *envp; envp++) 50 puts (*envp); 51 exit (0); 52 } 53 54 /* printenv varname */ 55 len = strlen (*argv); 56 for (envp = environ; *envp; envp++) 57 { 58 if (**argv == **envp && strncmp (*envp, *argv, len) == 0) 59 { 60 eval = *envp + len; 61 /* If the environment variable doesn't have an `=', ignore it. */ 62 if (*eval == '=') 63 { 64 puts (eval + 1); 65 exit (0); 66 } 67 } 68 } 69 exit (1); 70} 71 72