Creating My Own Shell…..


Subi_Prabhakaran

Let me start with some of the basics I learnt while learning to do this…

In its simplest form a Shell is a program that takes the command from the user and gives it to the operating system so that the corresponding action can be performed. In short a Shell is a command interpreter, which provides an interface for users of an operating system which provide access to services of the kernel.

There are many different shells:

  • sh(Bourne Shell)
  • bash(Bourne Again Shell)
  • ksh
  • csh

The following is the C code for a very simple shell..

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

#define MAXLINE 1024

int main(void){
char buf[MAXLINE];
pid_t pid;
int status;

printf(“%% “); /* print prompt (printf requires %% to print %) */
while (fgets(buf, MAXLINE, stdin) != NULL) {
buf[strlen(buf) – 1] = 0; /* replace newline with null */

if ( (pid =…

View original post 218 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s