If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Shell Program

Hello everyone! I was wondering if anyone can assist me in writing a linux shell in c++. I am having trouble writing this simple shell.The Shell must support these commands:

i. cd <directory> - change the current default directory to <directory>. If the <directory> argument is not present, report the current directory. If the directory does not exist an appropriate error should be reported. This command should also change the PWD environment variables.
ii. clr - clear the screen
iii. dir <directory> - list the contents of directory <directory>
iv. environ - list all the environment strings
v. echo <comment> - display <comment> on the display followed by a new line (multiple spaces/tabs may be reduced to a single space)
vi. help - display the user manual using the more filter
vii. pause - pause operation of the shell until 'Enter' is pressed/
viii. quit - quit the shell
ix. The shell environment should contain shell = <pathname>/myshell where <pathname>/myshell is the full path for the shell executable (not a hardwired path back to your directory, but the one from which it was executed)

Reply to Zak

Yes, my program has to be a stand alone program. It must run on it's own without using the commands that are already there. I am uncertain of how it would work as a stand alone program and that is why i need help.

Yes, I agree with jonnin^. Thats the beauty of Linux. It's all open source. Just pick a distro of linux you like (i.e. Fedora is a good one.) and download the "source" iso. That would be the best way...
-Zak

I don't know about this. Reading the source file of a real world professional sheel program can be an overwhelming experience for a beginner. What I suggest is writing a rudeminteray shell that supports one command and one paramter and then extend it to suppoer more paramers. Note that the important thing is to get the commands parsed correctly; the shell doesn't have to support every possible option but it has to detect typos, incorrect parameters etc.
Nomrally, the program consists of one big loop that reads input, parses it and executes it.

Reply to Danny

Yes, I understand what you are telling me but the thing is that I am unable to traslate it into code. Is there any way that you can start me off by showing me the quit and clear commands. I am totally lost and do not know what I am doing. Thanks.

Personally, I would just mask the commands that exist (for example, dir is just ls-la or some similar commandline option on ls) -- linux lets you alias (is that spelled right?) commands to a new name. That way, you still have a 'real' shell behind you (environment variables, paths, etc). Just a thought, if you only want to emulate a few dos commands...