Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to write a UNIX - like shell program that works in our Linux machine in Lab FH 1 3 3 E .

Your task is to write a UNIX-like shell program that works in our Linux machine in Lab FH 133E. A shell is a command line interface for users.
It accepts usercommands and execute them. Under the hood, a shell is just another user program. For eamples, /bin/sh,/bin/bash,/bin/tcsh, etc.,
are popular shells in Unix/Linux systems. In this assignment, you will implement your own shell, named as "myshell".
[30 points] Your shell should repeatedly display a prompt and allow the user to enter a command to run. Your shell is supposed to read the input from system standard input, parse the line with command and arguments, and execute. You must use fork() and execv() system calls.
Given a user command, your shell should try to find the build-in commands (see part2) first. If not found, it should search the directories stored in the pathname environment (your impelementation). For example, if "/bin" appears in the pathname environment, your shell should automatically support most Linux shell commands.
You are not allowed to use system() or any similar function that invoke the system's /bin/sh shell. Again, you are only allowed to use fork() and execv() to create a process and execute the user command. Note that you cannot use execlp() or execvp() because these will use the system's pathname environment.
By convention, the command arguments are separated by white spaces. Your implementation should follow this rule. Your shell does not need to handle special characters like ",?,|,\, &", except input redirection "<" and output redirection ">".
If the user command cannot be found, i.e., neither a build-in command nor a command can be found in the directories contained in the pathname environment, your shell must give a meaningful response and then continue display a prompt for the next command.
[30 points] Build-in commands:
cd: is a command that changes directories. You should use chdir() system call to achieve it.
path: is not only a command that shows the current command searching pathname environment (if no argument is given), but also a utility to modify the pathname environment.
path (without argument): display the current pathname environment, e.g.,"/bin:/sbin". Note, your shell starts with an empty pathname environment.
path +/abc/def: appends directory "/abc/def" to the end of the pathname environment.
path -/abc/def: removes pathname "/abc/def" from the pathname environment if it exists. Otherwise, do nothing.
quit: a command to terminate your shell.
[30 points] Extend your shell to support I/O redirection: input redirection "<" and output redirection ">". You must use open(), close(), and dup() system calls. Your shell does not need to handle redirection for above build-in commands. Note that either "<", or ">", or both may appear in a user's command.
[10 points] README and makefile: must be a text file (not a PDF, docx, or rtf). Document your design ideas in this README file. In particular, provide an instructions how to compile your code, how to run your program, and provide a sample test output (again in text format). Finally, provide a statement if your code contains any bugs or miss a certain component. You must provide a makefile such that the grader can compile your code by simply typing "make".
System input and output rules: in this project, you can only use fgets() function to take the keyboard inputs, e.g., fgets(buffer,1024, stdin) will capture a user command in a pre-prepared buffer with size of 1024 bytes. For system output, you should use printf() function. All file input/output must be performed via system calls, including open(), close(). The library calls such as fopen(), fread() are not allowed in this project.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions