Advertisement
the_austria

Shell Simulator

Jul 7th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. '''
  2. Shell-Simulator 0.0.2
  3. by Felix Oesterreicher
  4. 07-07-2012
  5. '''
  6.  
  7. dir=["home","felix"]  # directory to start with
  8. x = ""
  9.  
  10. while True:
  11.  
  12.   # Set the working directory
  13.   wd= ""
  14.   if dir==[]:
  15.     wd="/"
  16.   else:
  17.     for i in range(0,len(dir),1):
  18.       wd+="/"+dir[i]
  19.  
  20.   # Get the command ( x - raw command , y - list of args )
  21.   x= input (wd+"$ ")
  22.   y= x.split()
  23.  
  24.   ''' the possible commands '''
  25.  
  26.   # exit
  27.   if y[0]=="exit":
  28.     break
  29.    
  30.   # cd
  31.   elif y[0]=="cd":
  32.     if len(y)<=1:
  33.       dir=["home","felix"]
  34.       continue
  35.     if y[1][0]=="/":    
  36.       dir=y[1].split("/")
  37.       del dir[0]
  38.     elif y[1]=="..":
  39.       if not dir==[]:
  40.         del dir[-1]
  41.     elif y[1]==".":
  42.       pass
  43.     else:
  44.       dir.append(y[1])
  45.      
  46.   # pwd
  47.   elif y[0]=="pwd":
  48.     print(wd)
  49.    
  50.   # command not found
  51.   else:
  52.     print ("Command not found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement