Question
You are required to develop a simple Linux shell in C language “shell.c".
The shell has to perform the following requirements: - - The shell prompt is “"myshell>".
- Run commands either from current directory or from “/bin" directory using the "exec" system call.
- Support output redirection like "command> filename" using "dup" system call. Note: save the output of the comment in the (filename).
- Implement the “history shell command to list the last ten commands entered so far.
- Implement the "clear" shell command to empty the history commands.


PLEASE Make sure you handle all cases, exceptions and cover possible user mistakes with clear and proper messages.



You are required to develop a simple Linux shell in C language shell.c. The shell has to perform the following requirements
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MYSHELL:

=======================================================================

#include<stdio.h>

#include<unistd.h>

#include<string.h>

int main()

{

char command[20]; //storing the input

while(1){

printf("myshell>");

scanf("%s",command);

if(strcmp(command,"history")==0) //HISTORY

{

char *tailPath="/usr/bin/tail";   //tail path

char *cmd="tail";   //tail is the command

char *filename="/home/Myshell/.bash_history"; //history is stored in .bash history file of a user's home directory

execlp(tailPath,cmd,filename,NULL);   //call execlp

}

else if(strcmp(command,"clear")==0)   //CLEAR

{

char *rmPath="/bin/rm"; //we can delete history file using rm command

char *cmd="rm";

char *filename="/home/Myshell/.bash_history";

execlp(rmPath,cmd,filename,NULL);

}

else

{

printf("Invalid command\n");

}

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
You are required to develop a simple Linux shell in C language “shell.c". The shell has...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Overview Writing in the C language, implement a very basic shell, called smash. In this project,...

    Overview Writing in the C language, implement a very basic shell, called smash. In this project, we will work on processing strings and using the appropriate system calls. Build System setup Before we can start writing code we need to get our build system all setup. This will involve writing a very simple makefile. You should leverage your Makefile project for this part of the assignment! Write a Makefile that provides the three targets listed below all - The default...

  • Using Unix processes Submit a README file that lists the files you have submitted along with...

    Using Unix processes Submit a README file that lists the files you have submitted along with a one sentence explanation. Call it Prj1README. MakeCopy.c : Write a C program that makes a new copy of an existing file using system calls for file manipulation. The names of the two files and copy block sizes are to be specified as command line arguments. Open the source file in read only mode and destination file in read/write mode. ForkCopy.c : Write a...

  • Project 1: Implementing a Shell 1 Overview In this individual project you will have to design...

    Project 1: Implementing a Shell 1 Overview In this individual project you will have to design and implement a simple shell command interpreter called mysh. The basic function of a shell is to accept lines of text as input and execute programs in response. The shell must be able to execute built-in commands in a process different from the one executing mysh. 2 Requirements When first started, your shell should initialize any necessary data structures and then enter a loop...

  • write the following code using C language. It will be ran in Ubuntu running linux OS...

    write the following code using C language. It will be ran in Ubuntu running linux OS 2 File Management System Write a basic file managment system with following capabilities. Suppose the name of the program is myFS. When it executes as below: myFS Is - /home Figure 6 : First command format The program should provides the file listing of the given directory. The program should list the filename, file size, and time last modified for each file within the...

  • LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check...

    LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check the output) Display the command(s) used to do the following: create an empty file called history by using just a redirection operator. Verify and show. Show/verify all results (i.e., all commands and their corresponding outputs). Wait 1 minute or more and then display the command(s) used to do the following: change the timestamp on the history file you just created. Verify/display the change. Show/verify...

  • b. echo Your file has been processed c. echo l; d. cp file /tmp 36. You...

    b. echo Your file has been processed c. echo l; d. cp file /tmp 36. You can use the command to start a program with an environment variable setting that is not part of your current environment. c. use d. env a. export b. set 37. The command displays a list of all environment variables defined in your current environment. c. use d. env a. export b. set he environment variable contains a list of directories on the Linux system...

  • C program To develop a C program to implement a process system call. PROBLEM You are...

    C program To develop a C program to implement a process system call. PROBLEM You are to use the Ubuntu operating system to write a C program that creates a process to determine the identification of the current user of your computer. I mean if joe is the login of the current user of your computer your solution should return joe. Your solution must also provide the pid of both the parent and the child processes. You may use the...

  • Update the program in the bottom using C++ to fit the requirements specified in the assignment....

    Update the program in the bottom using C++ to fit the requirements specified in the assignment. Description For this assignment, you will be writing a single program that enters a loop in which each iteration prompts the user for two, single-line inputs. If the text of either one of the inputs is “quit”, the program should immediately exit. If “quit” is not found, each of these lines of input will be treated as a command line to be executed. These...

  • Tokeniser in C++

    TokenisersBackgroundThe primary task of any language translator is to work out how the structure and meaning of an input in a given language so that an appropriate translation can be output in another language. If you think of this in terms of a natural language such as English. When you attempt to read a sentence you do not spend your time worrying about what characters there are, how much space is between the letters or where lines are broken. What...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT