ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I want to write my own Linux shell in c/c++ for my college project . All i know as of now is a few system calls .Any siggestion pliz. HOw about some good books , good sites that will help me write my own Linux shell and i plan to call it
eshell e for easy - it will be menu base , for the very freshies
"Unix for Users and Programmers" by Graham Glass http://search.barnesandnoble.com/tex...sbn=0136816851
When I had my UNIX class it was the course's book, and it helped me a lot in my Operating System class where I had to do a presentation on storage devices and management of free space in modern operating systems.
P.S. Almost forgot to say, this book has an example of a complete shell called something "internet shell"- just don't copy it - understand it.
If you are going to do this for a final project, then I suggest you think of some creative ideas. Creating a basic shell that can copy, cut, paste, echo, cat, and run programs isn't too hard. Think of some things that you normally do that you think could be streamlined or shortened. The sky is the limit. Just make sure you clean up after all your child processes and watch for memory leaks.
Good luck and let us know how it goes.
-biosx
PS: I instead of the EShell, you should call it the EzShell. There is already an EShell based off of Emacs (just like Eterm).
What exactly do you want your shell to do? If you want it simply to run commands, that's easy. Adding bg/fg support isn't too hard either. The annoying part is cleaning up processes
hi
I was wondering did you ever manage to write that shell. If you did please could you send it to me at g99m2638@campus.ru.ac.za. I have to do this for a prac at university and I am really struggling.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main( int argc, char *argv[] )
{
char cmdStr[256], *user, hostname[256];
memset(hostname, 0x00, sizeof(hostname));
gethostname(hostname, sizeof(hostname));
user = (char *)getenv("USER");
if( user == NULL )
{
strcpy(user, "unknown");
}
while(1)
{
printf("%s@%s: ", user, hostname);
memset(cmdStr, 0x00, sizeof(cmdStr));
/*
* use fgets instead of gets. don't wanna be exploitable!
*
* remember that fgets traps everything typed into the command
* line, event the carriage return!
*/
fgets(cmdStr, sizeof(cmdStr), stdin);
if( strncmp("quit", cmdStr, 4) == 0 )
{
/*
* exit
*/
break;
}
else if( strncmp("set", cmdStr, 3) == 0 )
{
/*
* set an environment variable
*/
//setenv(parm1, parm2, true);
printf("environ var not set\n");
}
else
{
/*
* Sure, I'm cheating. You'd have to be a masochist (sp) to
* do otherwise.... or your professor requires it.
*/
system(cmdStr);
/*
* futher thought says one could use execve()/execvp()
* to handle processes. but you'll want to parse out
* command line arguments and stuff
*/
}
}
return 0;
}
I'll be glad to try to give pointers to those that need help writing a shell.
Ladies and gentlemen,
Thanks a lot for all ur kind replies. As of now the shell that i plan to write is only an idea. I plan to materialize it only in the next year for my final year college project . And it will be very preliminary . I want to do it mainly bcoz i just wanna do something different . The guys here heartly knows Linux . Of cousrse they know Unix , the name itself and a few simple commands . I just can do an app project in VB , Oracle , MS acccess (not that they are bad) . I need to do something different. I am not even sure if my college will allow me to do this , something on Linux platform becuase they hardly look beyond Windows and never peep thru them . As of now i know less or nothing in system prg . But guys tell me i can do it . I am going to do it .
Thanks 4 ur co - operation guys.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.