-
1. Prompt Display: Displays a prompt
minishelland waits for user input. -
2. Command History:
- minishell maintains a history of commands entered by the user.
-
3. Command Execution:
- minishell searches for and executes the correct executable based on the
PATHenvironment variable or using a relative or absolute path. - minishell does not need to handle unclosed quotes or special characters like
\or;.
- minishell searches for and executes the correct executable based on the
-
4. Quote Handling:
- Single Quotes (
'): Prevent the shell from interpreting meta-characters within the quotes. - Double Quotes (
"): Prevent the shell from interpreting meta-characters within the quotes except for the$character.
- Single Quotes (
-
5. Redirections:
- Input Redirection (
<): Redirects input from a file. - Output Redirection (
>): Redirects output to a file. - Append Output Redirection (
>>): Appends output to the end of a file. - Heredoc (
<<): Reads input until a delimiter is found.
- Input Redirection (
-
6. Pipes (
|):- minishell supports pipelines, allowing the output of one command to be the input of another.
-
7. Environment Variable Expansion:
- minishell expands environment variables prefixed with
$followed by a sequence of characters into their corresponding values. - minishell handles $? which should expand to the exit status of the most recently executed foreground pipeline
- minishell expands environment variables prefixed with
-
8. Signal Handling:
- minishell handles signals like
Ctrl+C,Ctrl+D, andCtrl+\appropriately, using at most one global variable for signal handling. -
Ctrl+C(SIGINT): Displays a new prompt on a new line. -
Ctrl+D: Sends an EOF character which can be detected as an empty input fromreadline. Exits the shell. -
Ctrl+\(SIGQUIT): Does nothing.
- minishell handles signals like
-
9. Built-in Commands:
-
echowith-noption: Displays a line of text. -
cdwith a relative or absolute path: Changes the current working directory. -
pwd: Prints the current working directory. -
export: Sets environment variables. -
unset: Unsets environment variables. -
env: Displays the environment variables. -
exit: Exits the shell.
-
-
10. Memory Management:
- The shell handles memory allocation and deallocation properly. Memory leaks from the
readlinefunction are acceptable and do not need to be fixed. - suppressions.supp file is currently supressing the memory leaks caused by
readline(). To use it with valgrind, the command is:
valgrind --suppressions=suppressions.supp --leak-check=full --show-leak-kinds=all ./minishell
- If there are no other leaks from other functions other than
readline(), the output afterexitis going to be something like:
==00001== LEAK SUMMARY: ==00001== definitely lost: 0 bytes in 0 blocks ==00001== indirectly lost: 0 bytes in 0 blocks ==00001== possibly lost: 0 bytes in 0 blocks ==00001== still reachable: 0 bytes in 0 blocks ==00001== suppressed: 204,161 bytes in 221 blocks
- The shell handles memory allocation and deallocation properly. Memory leaks from the
- Standard C library:
malloc,free,write,read,close. - Input/Output:
readline,rl_clear_history,rl_on_new_line,rl_replace_line,rl_redisplay,add_history,printf,perror,strerror,isatty,ttyname,ttyslot,tgetent,tgetflag,tgetnum,tgetstr,tgoto,tputs. - Process Control:
fork,wait,waitpid,wait3,wait4,kill,exit,execve. - Signal Handling:
signal,sigaction,sigemptyset,sigaddset. - File Operations:
open,access,stat,lstat,fstat,unlink,opendir,readdir,closedir,dup,dup2,pipe. - Environment:
getenv,tcsetattr,tcgetattr. - Directory:
chdir,getcwd. - Terminal Control:
ioctl.
For clarity, in the commit history, we use the following prefixes
feat:for new features and major functionalities.fix:for bug fixes or corrections.docs:for documentation updates.style:for code style improvements and refactoring.
-
Create a New Branch:
git checkout -b branch-name
-
Push New Branch to GitHub:
git push -u origin branch-name
-
Stay Updated with Main Branch:
git checkout main git pull git checkout branch-name git merge main
-
Merge Branch into Main:
git checkout main git merge branch-name git push
-
Delete a Branch:
git branch -d branch-name git push origin --delete branch-name
- Resolve Conflicts: If there are any merge conflicts during the
git mergestep, Git will notify you. You'll need to manually resolve these conflicts in the affected files, then add and commit the resolved files.
- Main Loop: Core loop handling prompt display and user input.
- Input Handling: Reading and preliminary processing of input, including checking for unclosed quotes.
- Lexer/Tokenizer: Breaking input into tokens (words and operators).
- Parser: Constructing command structures from tokens, handling syntax rules.
- Expander: Handling environment variable expansion and wildcard expansion.
- Executor: Executing commands, managing built-ins and external commands.
- Built-in Commands: Implementing the required built-in functions.
- Environment Management: Handling environment variables and their manipulation.
- Redirections: Managing input/output redirections and heredocs.
- Pipes: Handling inter-process communication via pipes.
- Signal Handling: Managing signals (
ctrl-C,ctrl-D,ctrl-\). - History Management: Implementing command history using the
readlinelibrary. - Utilities: Helper functions and common utilities.
- Error Handling: Providing user-friendly error messages and handling exit statuses.
- Memory Management: Ensuring all allocated memory is properly freed.
- Student Project Documentation:
- Minishell by Maia de Graaf and Alfred Polycarpe: Provided insights into project structuring and implementation details.
- Minishell by Vportens: Offered a breakdown of parsing, built-ins, redirections, and execution.
- Books:
- Advanced Programming in the UNIX Environment by W. Richard Stevens: Comprehensive resource on Unix system calls and process management.
- The Linux Programming Interface by Michael Kerrisk: Detailed explanations of Linux system programming concepts.