Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this exercise we will implement a simple shell in the C language under the Linux operating system. The shell will display a prompt to

In this exercise we will implement a simple shell in the C language under the Linux operating system. The shell will display a prompt to the user, read the commands and send them to the operating system for execution. and the three characteristics detailed in "Introduction and background" and they are (1) alias (2) prompt and (3) running
script file
General requirements from the shell will be as follows:
1. Input of a command from the user
The maximum length of the command including the arguments is 1024 characters.
The maximum number of arguments is 4. If there are more than 4 arguments, the command will be defined as invalid
No limit can be placed on the number of characters of each argument (or of the template name) but their sum is less than 1024!
There can be several spaces between one argument and another, but it can be assumed that there are no other characters between them (such as ('r','\t\'
2. Running the command
The commands will be sent to the operating system for execution using the execvp | commands fork. The lecture will be by having the program generate a child process. The son will be the one who will actually run the command using the execvp command - details given in class and practice
3. The shell will exit when the string exit_shell is typed. When the shell exits - it will print to the screen the number of commands including dashes (only a number will be printed without any additions) for example if one of the commands was "echo "hi assaf 1 will be printed 4. The structure of the prompt required in the exercise
#cmd: | #alias: | #script lines:>
The details of the elements in:prompt-
#cmd::
Represents the number of legal commands (commands) that have been successfully executed in the shell since the start of the run. Valid commands are commands that the system was able to run without errors.
#alias::
Represents the number of aliases currently active in the system. An active alias is a shortcut to a command that was defined by the user using the alias command and was not removed using the unalias command.
#script lines::
Represents the total number of command lines - valid or invalid. (which have been run from scripts (source) since the start of the shell's run.
prompt-example for
In this example:
Five valid commands were executed successfully.
#cmd:5]#alias:31#script lines:20>
Three active aliases are currently configured.
Twenty command lines were run from scripts.
The prompt must be updated every time a valid command is executed, an alias is set or removed, or a command line is executed from a script.
5. Alias definition
Defining an alias when the user types a command in the following structure:
alias ='
The program must define as a shorthand for the command, for example:
will define || In short for the command |- Is run alias when the user types a command defined in alias on the program
alias ll='ls -l'
Replace the command with the full command before executing it. for example:
will cause a run
Is -|
Displaying an alias When the user types only an alias, the program must display all the
-aliases defined as a list. for example:
Introduce:
Removing an alias when the user types a command in the following structure:
The program should remove the abbreviation II
6. Script files
Reading a script file:
As for the user typing a command in the following structure:
II='ls -l'
alias
unalias 11
source
The program must read the file

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

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

11.1 Explain the strategic importance of total rewards.

Answered: 1 week ago

Question

11.3 Define pay equity and explain its importance today.

Answered: 1 week ago