Writing your own shell in php

I’ve always wanted to write my own simple shell in php.  Call me a glutin for punishment, but it seems like something that a lot of people could use to be able to do… If your web app had a command line interface for various things… like looking up stats, or users, or suspending naughty accounts, or whatever…. wouldnt that be cool and useful?  Talk about geek porn.  Anyways this this morning I got around to tinkering with the idea, and here is what i came up with… It’s rough, and empty, but its REALLY easy to extend and plug into any php application.

apokalyptik:~/phpshell$ ./shell.php

/home/apokalyptik/phpshell > hello

hi there

/home/apokalyptik/phpshell > hello world

hi there world

/home/apokalyptik/phpshell > cd ..

/home/apokalyptik/ > cd phpshell

/home/apokalyptik/phpshell > ls

shell.php

/home/apokalyptik//phpshell > exit

apokalyptik:~/phpshell$ ./shell.php

See the source here: shell.phps

Comments (6)

  1. Joseph Scott wrote::

    Have you looked at phpsh (http://www.phpsh.org/)?

    Monday, August 4, 2008 at 1:00 AM #
  2. Apokalyptik wrote::

    I hadn't seen that one… I saw another one a while ago… I actually don't mean this to be a shell in the sense that bash is a shell you work on your system inside of, but an interface to an application.

    I imagine being able to, say, manage my wordpress blog posts with a simple class and the command line… or whatever…

    Mainly though it's an academic exercise. Just something I always wanted to try :D

    Monday, August 4, 2008 at 1:34 AM #
  3. Adam wrote::

    do you know how to make a simple shell in C?

    Thursday, September 18, 2008 at 10:42 AM #
  4. apokalyptik wrote::

    haha… I wish I did. I've never been that handy with compiled languages.

    Friday, September 19, 2008 at 3:12 AM #
  5. Adam wrote::

    The d/l link is broken.

    Tuesday, July 20, 2010 at 2:35 AM #
  6. apokalyptik wrote::

    Thanks for noticing! I've fixed it.

    Cheers!
    DK

    Tuesday, July 20, 2010 at 2:38 AM #