您的位置:首页 > 运维架构 > Shell

一个小巧的Python Shell

2005-09-13 10:04 549 查看
.comment {color:#009900}
.keyword {color:#0000FF; font-weight:bold}
.string {color:#999999}
.number {color:#FF0000}
.buildinfunctions {color:#FF0000}
.methods {color:#009999}
.attributes {color:#009999}
.exceptions {color:#FF0000}
.op {color:#993300}
.commonlibs {color:#660066}
.userdefine {color:#0000FF}

#!/usr/bin/python
# -*- coding: cp936 -*-

#################################
#   Written by caocao           #
#   caocao@eastday.com          #
#   http://nethermit.yeah.net   #
#################################

import os
import sys
import string
import re

print "Written by caocao"
print "caocao@eastday.com"
print "http://nethermit.yeah.net"
print

if os.name=="nt":
print "OS: Windows NT"
else:
print "OS: Unknown"
print "Python Shell Version 1.0"
print
while True:
try:
command=string.strip(raw_input("PS "+os.getcwd()+">"), " ")
commandLow=string.lower(command)
except EOFError:
break
else:
if commandLow=="exit" or commandLow=="quit":
break
elif commandLow=="":
continue
elif re.match("^[a-z]{1}:$", command, re.I)!=None:
try:
os.chdir(command)
except OSError:
print "No such file or directory"
elif re.match("^cd (.+)$", command, re.I)!=None:
matchObject=re.search("^cd (.+)$", command, re.I)
if matchObject!=None:
try:
os.chdir(matchObject.group(1))
except OSError:
print "No such file or directory"
else:
print "Bad command"
else:
os.system(command)
print
print "Byebye!"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: