We are given to implement a shell that supports a semi-colon separated list of commands. We need to use 'strtok' to tokenize the command. Also, support '&' operator which lets a program run in the background after printing the process id of the newly created process.
- A makefile along with all the source files have been included in the assignment submission
- Run
makecommand to compile and link the shell files - Run
./mainto execute the main shell program
-
Many commands are inbuilt which are explained in the following section. All the other commands which are to be executed in foreground and/or background are implemented using
execvp. So, all the commands available in Bash can be executed as well in this shell. -
The prompt for taking the next command displays the
username,hostnameand thepresent working directory. The directory in which the shell is run is taken to be the home directory~of the shell. The present working directory is displayed either in terms of/(if present working directory is the root of this shell) or as absolute path. -
This shell implements the usual commands of the linux shell like
cd,echoandpwd. Variations of these commands are also supported by this shell. -
lscommand has also been implemented along with its two flags namely-aand-l, along with '.', '..', '~', and directory paths as arguments. -
This shell also supports creating foregroud and background processes with the use of
&symbol. -
pinfois included as a command to display some specific information about the current self process or any other process when supplied with that process' PID. -
searchcommand searches for the presence of specific files recursively starting from the current working directory. -
This shell also supports IO redirection using symbols
<,>and>>. -
This shell also supports pipelining as in the original bash shell. Multiple commands can be chained together using the pipe
|symbol to pipe the output of one command to the input of another. -
Support for simple signals like CTRL + Z (SIGTSTP), CTRL + C(SIGINT) and CTRL + D(EOT) have been included with their appropriate behaviour
-
Autocomplete functionality for commands as well as files have been included to help the user with autocomplete functionality. Appropriate error messages are displayed when autocomplete does not find matching commands, files or directories.
-
history <num>command implements the history feature which prints 'num' number of previous commands entered by the user. Maximum storage capacity of history is 20 and maximum commands output is 10 (by default)
-
echo- Implemented in
echo.cpp - Takes a string argument and prints it after removing the extra spaces.
- Implemented in
-
pwd- Implemented in
pwd.cpp - Prints the path of current working directory.
- Uses the
getcwd()system call.
- Implemented in
-
cd [location]- Implemented in
cd.cpp - Changes the current working directory to the mentioned directory. If no parameter is given, it changes the directory to the root directory of the shell.
- If
~is present in the givenlocation, it is replaced with the home directory of the shell. - If
locationis-, it is interpreted as the previous working directory of the shell. - Implemented using
chdir()system call.
- Implemented in
-
ls [-l -a -al -la] [Directory]- Implemented in
ls.cpp - Lists all the files and directories in the mentioned directory/directories. If no parameters are passed, lists the contents of current directory.
-lflag lists the long format ofls, providing additional details such as permissions, owner, time of creation etc.-aflag includes the hidden files/diectories in the listing.- The flags and directories can be provided in any order.
- Uses the
readdir()system call.
- Implemented in
-
pinfo [process_id]- Implemented in
pinfo.cpp - Gives the information about
process_idprocess. Ifprocess_idnot mentioned, gives information about the current process. - The information includes Process ID, Process Name, State of the process and the exceutable path of the process.
- Uses the files
/proc/process_id/statusand/proc/process_id/execto fetch the required information.
- Implemented in
-
history [num]- Implemented in
history.cpp - Gives the
numnumber of previous commands run. Ifnumis not mentioned, 10 is taken as the default value fornum. - Continous repetitions, invalid commands and blank lines are avoided in the history.
- Implemented in
-
fg- Implemented in
main.cpp - Makes a foreground process and blocks the shell until the process exits or is forced to exit
- Implemented in
-
bg_process &- Implemented in
background.cpp - Creates a background process and resumes the terminal for command processing
- Implemented in
-
exit- Implemented in
main.cpp - Logs out of the terminal.
- Use this command to ensure proper closing (killing all persisting background processes).
- Implemented in
-
Any command ending with
&is treated as a background process the shell does not wait for its execution. If such a process requests terminal control, it will automatically suspended in the background. The shell keeps track of all background processes and alerts the user on their completion. -
| is used for piping of commands, i.e, Output of one command serves as input for the next. Example:
username@hostname $ cat todo.txt | head -7 | tail -5 -
< is used for input redirection. > (for overwriting) and >> (for apending) are used for output redirection.
Example:# Input Redirection username@hostname $ cat < todo.txt # Output Redirection username@hostname $ ls -l > list_dir.txt # Input and Output Redirection username@hostname $ cat < lines.txt > lines_copy.txt -
Ctrl + C sends the
SIGINTsignal and terminates any foreground process. -
Ctrl + Z sends the
SIGSTPsignal and suspends any running foreground process. -
Ctrl + D is an
EOFcharacter and terminates the shell.
- UP arrow key for command-recall
- Handle edge case of echo command
- pinfo - add + for foreground
- fix encoding for GUI apps when started with execv()
- Implement redirection with pipes