-
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)
If anyone can assis me with this I would appreciate it. Thanks.
-
Is this shell going to run on top of BASH or is it made to be a stand-alone shell?
The reason I ask this is because if it runs on top of bash you can just use the system() funtion to call bash commands...
-Zak
-
If the shell is meant to support one command, you can use command line arguments. Your program essentially has to read the arguments, prase and validate them.
You can read about command line arguments here
and here
As for environment variables, you can find more information here .
Danny Kalev
-
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.
Last edited by none_none; 04-17-2005 at 07:31 PM.
-
Reply to Danny
Yes, I am supposed to do exactly that. The thing is that I am not sure how. Can you help me out?
-
Your probably going to have to look at the source code for the existing shells and see what is required then.
-
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.
Danny Kalev
-
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.
-
near-code, you have to fill in around it but the general idea:
int main()
{
while(!done)
{
cin.getline(in);
switch(in)
{
case "quit" :
{
cleanup(); //do whatever you need to before exit
done = true;
break;
}
case "command" :
{
do_command();
break;
}
}
}
}
-
Reply to jonnin
Thanks man! I really appreciate it much. I will see what i can do and then ask you more questions if I am stuck. This helps some. 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...
-
Reply to jonnin
Is there any way that you can show me how to mask the commands. I am still struggling with this shell and need to actually see what you are talking about. Thanks.
-
http://www.computerhope.com/unix/ualias.htm
if you put such a command into your .profile or whatever those strange, sort of hidden files are called, its always there for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks