This project is my Final Project at 42 for the UNIX System specialization. Me and my team worked on this project for 5 months toward the validation of our first specialization : UNIX System in C
Sources and Build found on this git are a copy of the files we turned in for the project validation. I did it so it can be easily clone, make and run regardless of access to external libraries and sources. The Codebase was also cleaned for the validation. The downside of this is it doesn't show the original git history. If you are interested in it, you can check the original project here
Note: The project on the original won't compile because you won't have access to our LibC implementation submodule. Moreover, a lot of last optimization and codebase fix where done on the repository given to us for the project validation. Thus for anything besides looking at git history, this repository is more reliable than the original.
This project was done as a team effort with :
Links to their GitHub page included.
The goal of this project was to implement a rather complete UNIX Shell regarding POSIX Standards. During our UNIX System specialization at 42, we had to first get to work with UNIX File system, Shellscript, Signals, Syscall, Shell Environnement, Binaries and Built-ins along with a lot of C design patterns. This project was the perfect use case to bring it all together to implement our own shell using C with no external library or functions, from scratch.
Besides all the project requirements, we had to implement a few libraries to build our architecture.
- Hash table library. Find more here
- Our implementation of
printf
as the standard one is forbidden by the project. Find more on thelibft
directory of this project. - A State Machine library for Lexing, Parsing, and Execution. Find more on the
libft
directory of this project. - A Vector library to handle line editing and general string manipulation, as the standard one is forbidden by the project. Find more on the
libft
directory of this project. - Using our LibC implementation, as the standard one is forbidden by the project. Find more on the
libft
directory of this project.
Note: For a full understanding of this project, see
Subject_42sh.en.pdf
on this repository
To run this program :
- Clone this repository
git clone https://github.com/Nrechati/42sh-UNIX-Shell.git
- Just
make
./42sh
to run
Note: Program was built on macOS Mojave and I know there is some workaround to do to compile on Linux as well (mostly for syscalls)
As the project stipulates that the shell has to be based on an Official POSIX Shell, we chose bash --posix for our own. The project also says that this reference is a starting point and that some features or behaviors can differ from it as long as it is an implementation or architectural choice and not just for convenience.
For POSIX standards, we mostly relied on :
- Unix.com
- GNU.org
- The Open Group
- The Manual of Termcaps, for line editing in the shell
Alongside a lot of other documentation like GCC, one for Lexer/Parser or American Fuzzy Loop fuzzer for testing.
- Prompt
- Command execution with arguments
- $PATH management
- Homemade error handling (no errno), and process/shell return values
- Tab and Space in prompt management
- Redirections and fd aggregation :
>
,>>
,<
,<<
,>&
,<&
- Pipes :
|
- Commands separator :
;
- Logical operator
&&
and||
- Shell internal variables handling
- Variable assignation
name=value
- Variable export to environement via
export
built-in - Local variable assignation,
ls PWD=~/
- Special parameters managment :
$?
,$$
,$!
,$-
,$0
- Complete line editing management (Multiple lines, Copy, Paste, home, end, arrows, etc ...)
- Sub-prompt management
- Job control management
jobs
,fg
,bg
,&
operand, built-in to interact with jobs
- Signal managment
- Correct return value managment upon singals
"
double quotes,'
simple quotes and\
backslash inhibitors managment
- Simple expansion with
${}
and$
- Tilde expansion
${parameter:-word}
${parameter:=word}
${parameter:?word}
${parameter:+word}
${#parameter}
${parameter%}
${parameter%%}
${parameter#}
${parameter##}
- Post and Pre Increment and Decrement with
++
and--
- Addition and Subtraction
+
and-
- Multiplication, Division, Modulo with
*
,/
,%
- Comparison
<=
,>=
,<
,>
- Equality or not
==
and!=
- Logical AND & OR with
&&
,||
- Brackets and parentheses
{}
,[]
,()
- Full history management
- Expansion
!!
- Expansion
!word
- Expansion
!number
- Expansion
!-number
- Incremental research with
Ctrl + R
- Up and down arrow research in the history
- History file save
fc
Built-in
- Command and Built-in completion
- File completion
- Internal variables completion
- Hash table for binaries and built-ins
- Use of HashMap lib
hash
built-in according to POSIX standards
- Command execution with
-c
in batch mode - Piped command execution in batch mode
- cd
- echo
- exit
- type
- set
- unset
- export
- jobs
- fg
- bg
- fc
- hash
- pwd
- test