forked from ywangd/stash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintenv.py
32 lines (23 loc) · 846 Bytes
/
printenv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
########################################################################.......
"""List current environment variables and values.
"""
from __future__ import division, print_function, unicode_literals
import argparse
import os
import sys
def main(args):
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("variables", action="store", nargs="*",
help="variables to be printed")
ns = p.parse_args(args)
if ns.variables:
vardict = {k: v for k, v in os.environ.items() if k in ns.variables}
else:
vardict = os.environ
vardict = {k: v for k, v in vardict.items() if k[0] not in "$@?!#*0123456789"}
for k, v in vardict.items():
print("{}={}".format(k, v))
sys.exit(0)
if __name__ == "__main__":
main(sys.argv[1:])