Answered step by step
Verified Expert Solution
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 alias prompt and running
script file
General requirements from the shell will be as follows:
Input of a command from the user
The maximum length of the command including the arguments is characters.
The maximum number of arguments is If there are more than 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
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 rt
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
The shell will exit when the string exitshell 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 will be printed 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.
promptexample for
In this example:
Five valid commands were executed successfully.
#cmd:#alias:#script lines:
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.
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 llls 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
Script files
Reading a script file:
As for the user typing a command in the following structure:
IIls l
alias
unalias
source
The program must read the file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started