Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
[PYTHON]Simple shell
  • chroniccommand
    Posts: 1,389
    This is a very simple shell coded in Python. Here it is

    #!/usr/bin/python
    #Very simple system shell in python

    import os, sys
    done = False
    while not done:
    command = raw_input('PyShell$ ')
    os.system(command)

    This asks for input from the user, then executes it using the os.system command.
  • Bursihido
    Posts: 406
    i will try this later ...nice stuff thanks for share
  • Xin
    Posts: 3,251
    Good job! :) this will be very useful
    Xin
  • Cleaned/Re-coded in Python 3:
    #!/usr/bin/python
    #Very simple system shell in python

    import os, sys
    while 1:
    command = input ( 'PyShell$ ' )
    os.system ( command )
  • Xin
    Posts: 3,251
    Good job lolcoder :)
    Xin
  • chroniccommand
    Posts: 1,389
    said:


    Cleaned/Re-coded in Python 3:

    #!/usr/bin/python
    #Very simple system shell in python

    import os, sys
    while 1:
    command = input ( 'PyShell$ ' )
    os.system ( command )



    Nice lolcoder. Is there any difference between
    while not done:

    And
    while 1:

    I wouldn't know. But I would guess a syntax issue lol.
  • said:


    said:


    Cleaned/Re-coded in Python 3:

    #!/usr/bin/python
    #Very simple system shell in python

    import os, sys
    while 1:
    command = input ( 'PyShell$ ' )
    os.system ( command )



    Nice lolcoder. Is there any difference between
    while not done:

    And
    while 1:

    I wouldn't know. But I would guess a syntax issue lol.


    if done had a Boolean value of False, or 0, while not done is saying 'while done != True'
    in a Boolean context,
    1 is == to True
    0 is == to False
    while 1 is == to while True
    while True is saying while True == True keep repeat-ably executing the code block.
    Hope this helps.
    Anyhow, my code is more efficient.
  • DizzY
    Posts: 155
    O.o im soo confused my head is spinning. xD
  • @DizzY haha xD
    It's also worth noting, this isn't a shell, it's more of a shell on top of a shell, because os.system() just uses, the default system shell.
    To make your own shell, you'd need to keep a list of the system executables directories (actually, a few more things, you would need to track though.), and use the subprocess module to execute the applications, and you could use regex to parse, pipes, arguments, flags, functions, etc.