LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2007, 09:42 AM   #1
peedaro
LQ Newbie
 
Registered: Oct 2007
Posts: 19

Rep: Reputation: 0
creating a shell within a shell


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..
 
Old 10-19-2007, 09:52 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
yeah sure,
as soon as I get out of the shower i'll help.

anything else you want done after this?
 
Old 10-19-2007, 11:19 AM   #3
terrio
LQ Newbie
 
Registered: Jan 2007
Location: Halifax, NS
Distribution: Linux Mint 11
Posts: 29

Rep: Reputation: 15
The solution is to do some research, code the shell, test, make changes, test.... The project is for your benefit, so give it a try.
 
Old 10-19-2007, 11:31 AM   #4
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
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
 
Old 10-19-2007, 12:21 PM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,902

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
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.
 
Old 10-19-2007, 12:37 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The source code for Bash is relatively simple to interpret...
ta0kira
 
Old 10-20-2007, 06:16 AM   #7
peedaro
LQ Newbie
 
Registered: Oct 2007
Posts: 19

Original Poster
Rep: Reputation: 0
ok..i was just confused as to where to start..so thought wil seek some help..nwz thanks a lot everybody..
 
Old 10-22-2007, 01:49 AM   #8
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Here's a hint... use execl(). Use the man-page to learn more about this function.
 
Old 10-22-2007, 02:42 AM   #9
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
peedaro, what you asked against the forum rules, which is why some of the responses are not as welcoming as they might be. Specifically, the rule is:
Quote:
Do not expect LQ members to do your homework - you will learn much more by doing it yourself.
 
Old 10-23-2007, 09:52 AM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a shell k_raj_k Programming 5 08-29-2007 12:28 PM
creating a user with no shell fredanthony Linux - Newbie 8 07-18-2006 09:28 AM
Help with creating a shell script windisch Programming 66 10-07-2005 06:26 AM
creating a new user using shell only ? ( RH 9 ) CooLMaN Linux - General 4 04-04-2004 11:42 AM
Creating a linux shell with C CragStar Programming 2 10-02-2002 09:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration