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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello everyone
I am new to linux and have just started learning..i have been given a project where i have to implement a linux shell using c program..for the following commands
echo,pwd,date,mkdir,rmdir,ls,cp,rm,head,tail..please post the algorthim or the function or the source code for executing these commands to execute them in user-created shell..will be really grateful..
Did I get this right: you need to code, in C, a shell - so what are those commands you listed, that "need to be implemented"? pdf, date, echo etc. commands aren't what a shell is created to do, they're just programs that are run from a shell. If you tried to code all possible programs directly into the shell (rather than create them as separate executables that are then run from a shell), you got a huge sized shell executable that would always be difficult to maintain and extend - not to mention test for bugs.
1) you need to specify clearly that this is a project like schoolwork that you need to do in order to, for example, pass a course
2) you need to understand that nobody is doing that project for you, it's you who needs to do it (because that's the only way you'll learn anything from it)
3) you need to be clear and specific about what the exact job to be done is: a shell, a shell plus several executables, or executables, or what?
4) you need to stop throwing a project at people, start working on it, possibly face trouble and then ask for help for that specific troublematic situation, along with information about what you already have tried to do to solve the situation, why it didn't work, and so on
5) you should read the sticky (or not) threads about how and what you are supposed to post here, and what not -- especially about schoolworks/projects
So, for a start you could think the project assignment so you know exactly what is needed to be done. Then you should start off with it; if you can't get anywhere, it's ok, but at least you need to try. In case of trouble you should contact your tutor/teacher first, because s/he is primarily responsible for your project, and you are to her/him. If that doesn't work out, or you just want to, you may come here and ask about the situation you got stuck into, but if you haven't done anything for it at all, it's unlikely anybody wants to help you. Remember, that projects like this aren't given to you to make your life difficult, but because you are supposed to use your head and learn things from it.
Now, where did you exactly get stuck in? What was difficult? We do have answers, but it's you who needs to understand both the problem and the solution - it's not ready for you, you'll have to work it out, with help if needed
You couls study some existing code for shells -especially those which implement builtin command like what you mention. I'd suggest looking at some very simple shells like those used in busybox or dash. The simplest standalone shell to look at is probably msh, but dash is a more full-rounded shell with a few builtins which are in separate c files.
I've recently done some work with dash -adding about 40 builtins, as a way of learning a little bit of C. However, just a few days ago I found an archive of an extremely simple shell which someone had just begun to code. You might search or an archive called fstest.zip -just 3 small files and basically no working commands, but it could provide a starting point. Once you understand the basic functionality of the shell itself, study the code for different versions of the individual commands you want to implement as builtins.
I think there is one general answer of value to the original poster. There are within many shells, commands that are built into the shell, and are not external programs. There is value in learning this distinction, and how the implementations differ.
Your commandline parser will have to have a list of those commands which are internal, and a way of finding all of those which are not in that list. Finally, the shell must have a way of invoking the command or handling nonsense commandlines.
--- rod.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.