r/ProgrammingPrompts • • Nov 13 '14

Write Your Own Shell!

Write your own shell thread!

Inspired by the common second/third year university assignment, designed to teach you about processes, IPC and handling user input.

A shell is a command line interpreter, it takes commands from the user and executes them. A common example is Command Prompt on Windows or Bash often found on *NIX systems.

Checkout Wikipedia for more information on a shell (though if you're unfamiliar with what a shell is this may be too difficult for you).

Foreground and Background execution (&) Unnamed pipes ( | ) Input/output redirection (< and >) Comments (#) Built in commands (cd, exit, ?)

I did this assignment in third year and it was a blast. I recommend using C or C++ for this programming prompt. It could easily be implemented in many other languages too, though. There are plenty of resources on the web like this: http://linuxgazette.net/111/ramankutty.html

Will update when not on mobile. Sorry for not including more of a spec.

If you're an up and coming programmer who is interested in this post below and I'll write up a how to and my solution

21 Upvotes

4 comments sorted by

View all comments

Show parent comment

4

u/Northburns Mar 20 '15

To the best of my knowledge Java does not support 'exec' or similar so writing a "bash style shell" would be difficult.

The class System (in package java.lang) has a static method exec, which returns a Process object that gives access to the process's input and output streams.