LinuxQuestions.org
Visit Jeremy's Blog.
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
 
Thread Tools Search this Thread
Old 08-07-2002, 12:15 AM   #1
benjaminrtz
Member
 
Registered: Jul 2002
Location: India
Distribution: Ubuntu, Gentoo
Posts: 99
Thanked: 0
Wanna write a shell


[Log in to get rid of this advertisement]
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
benjaminrtz is offline     Reply With Quote
Old 08-07-2002, 01:10 AM   #2
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,153
Thanked: 1
dont sound very e asy


good luck


http://www.clarkson.edu/~tuinstra/cs...NIX_shell.html

Last edited by DavidPhillips; 08-07-2002 at 01:15 AM..
DavidPhillips is offline     Reply With Quote
Old 08-07-2002, 08:54 AM   #3
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704
Thanked: 0
"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.

Last edited by neo77777; 08-07-2002 at 08:56 AM..
neo77777 is offline     Reply With Quote
Old 08-11-2002, 05:38 AM   #4
GT I.N.C
Member
 
Registered: May 2002
Location: Australia, Sydney, St.Clair
Distribution: Rh 7.3
Posts: 836
Thanked: 0
have a look at www.desktopian.org
GT I.N.C is offline     Reply With Quote
Old 08-13-2002, 11:33 AM   #5
biosx
Member
 
Registered: Jul 2002
Location: Chicagoland
Distribution: Gentoo, Ubuntu
Posts: 63
Thanked: 0
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).

Last edited by biosx; 08-13-2002 at 11:37 AM..
biosx is offline     Reply With Quote
Old 08-13-2002, 07:55 PM   #6
tyler_durden
Member
 
Registered: May 2001
Posts: 125
Thanked: 0
when i had to do it i used "advanced programming in the unix environment" by stevens, its got the best coverage of system calls.

you could just cheat and use
system()
hehe
tyler_durden is offline     Reply With Quote
Old 08-15-2002, 11:45 AM   #7
warhorse
LQ Newbie
 
Registered: Aug 2002
Location: Pittsburgh
Distribution: Debian
Posts: 24
Thanked: 0
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
warhorse is offline     Reply With Quote
Old 08-16-2002, 04:58 AM   #8
da Perp
Member
 
Registered: Oct 2001
Location: the Netherlands
Distribution: Bear Linux (LFS 3.3)
Posts: 171
Thanked: 0
Quote:
PS: I instead of the EShell, you should call it the EzShell. There is already an EShell based off of Emacs (just like Eterm).
Eterm is from Enlightenment, you moron!
da Perp is offline     Reply With Quote
Old 08-27-2002, 03:40 PM   #9
hopeless
LQ Newbie
 
Registered: Aug 2002
Posts: 3
Thanked: 0
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.
hopeless is offline     Reply With Quote
Old 08-28-2002, 10:16 AM   #10
no2nt
Member
 
Registered: Aug 2001
Location: South Carolina, USA
Distribution: Redhat 8.0/Custom
Posts: 95
Thanked: 0
shell code - - -

Sounded like fun so here's a 5 min example:

Code:
#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.

Last edited by no2nt; 08-28-2002 at 10:35 AM..
no2nt is offline     Reply With Quote
Old 08-29-2002, 11:55 PM   #11
benjaminrtz
Member
 
Registered: Jul 2002
Location: India
Distribution: Ubuntu, Gentoo
Posts: 99
Thanked: 0

Original Poster
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.
benjaminrtz is offline     Reply With Quote
Old 10-19-2003, 06:39 AM   #12
SYED AMAN AYAZ
LQ Newbie
 
Registered: Oct 2003
Posts: 1
Thanked: 0
Lightbulb

All of you have very good responces thats y i am also posting a question regarding the same question?

Can any 1 give me coding of a shell program so that i also can study and submit it to my college as i also have the same assignment Thank you!
SYED AMAN AYAZ is offline     Reply With Quote
Old 10-19-2003, 03:00 PM   #13
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223
Thanked: 1
http://www.linuxquestions.org/questi...threadid=87812

Maybe this would help.Try to implement your own shell using it.
SaTaN is offline     Reply With Quote

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
wanna write a script djflix Linux - Newbie 4 09-07-2005 12:54 PM
Hint: Wanna try Linux, so wanna rig your Windows system to dual-boot? sundialsvcs Linux - Newbie 2 08-16-2005 03:56 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 04:00 PM
wanna write a driver sanglih Linux - Hardware 1 06-05-2002 08:22 PM
write own linux shell in C razza Programming 3 05-14-2002 03:02 PM


All times are GMT -5. The time now is 03:40 PM.

Main Menu
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.
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.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration