/* Program to Print Environment Variables * Program Name : prenv.c * */ #include <stdio.h> int main(int argc, char *argv[], char *envp[]) { int i = 0; while (envp[i]) { printf("Environment Variable : %s\n", envp[i]); i++; } return 0; } |
Print all the environment variables using extern variable environ.
/* Program to Print Environment Variables * Program Name : prenvv.c * */ #include <stdio.h> extern char **environ; int main(int argc, char *argv[]) { int i = 0; while (environ[i]) { printf("Environment Variable : %s\n", environ[i]); i++; } return 0; } |
The output of both the programs are same.
Program Output:
$ ./prenv Environment Variable : _=./prenv Environment Variable : HZ=100 Environment Variable : SSH_TTY=/dev/ttyp0 Environment Variable : PATH=/bin:/usr/bin:/usr/gnu/bin:/sbin:/usr/local/bin Environment Variable : HUSHLOGIN=FALSE Environment Variable : EDITOR=emacs Environment Variable : SHELL=/bin/ksh Environment Variable : HOME=/home/reemus Environment Variable : TERM=xterm Environment Variable : PWD=/home/reemus/prog/cprog Environment Variable : TZ=EST5EDT Environment Variable : ENV=/home/reemus/.kshrc $ |
No comments:
Post a Comment