42sh is the last project on the Unix path at 42. The goal is to write a fully-fledged shell, allowing the user to interact with our shell and execute commands. Please see the PDF file for more information.
The shell must be error-free: no bug is to be found whatsoever, no infinite loop, no memory leak, no segmentation fault, regardless of the user's potentially unexpected behavior. If you do find a bug, please report it via an issue!
This program was not programmed to be portable. Indeed, the code was written to be norme compliant. Let us outline the key rules of the norme:
- 25 lines per function maximum.
- 5 functions per .c file maximum.
- Comments only allowed outside of functions.
- Declaring static function whenever possible.
- All defines, and typedef must be done in header files.
- Defines in header files must be defined after includes.
This program will probably NOT compile on any other machine than macOS. Sorry for the inconvenience!
One-liner to download and run our shell :
git clone https://github.com/pscott/42sh.git ; cd 42sh ; make ; ./42sh
- Executing commands (
ls
,pwd
, etc...) - Line editing
- Left arrow to move the cursor to the left.
- Right arrow to move the cursor to the right.
- Home to move the cursor to the beginning of the command.
- End to move the cursor to the end of the command.
- Redirections (
>
,>>
,<
,<<
,>&
,&<
) - Pipes and logic operators (
|
,&&
,||
) - Command separator (
;
) - Posix compliant builtins (
cd
,echo
,exit
,hash
,type
,set
,unset
,export
) - Posix compliant job control (
jobs
,fg
,bg
,&
) - Quotes and backslashes (
'
,"
,/
) - Arithmetic expansion (
$((a + b))
)- Incrementing and decrementing (
++
,--
) - Addition, subtraction, multiplication, division, modulus (
+
,-
,*
,/
,%
) - Comparison (
>=
,>
,<=
,<
) - Equality (
==
,!=
) - AND and OR (
&&
,||
)
- Incrementing and decrementing (
- History:
- Up arrow to get the previously typed command.
- Down arrow to get the next command.
- Expansions (
!!
,!word
,!number
,!-number
) - Posix compliant
fc
builtin - Search in history with Ctrl+r
test
builtin along with different options:-b
,-c
,-d
,-e
,-f
,-g
,-L
,-p
,-r
,-S
,-s
,-u
,-w
,-x
,-z
,=
,!=
,-eq
,-ne
,-ge
,-lt
,!
- Copy / Cut / Paste:
- Enter/quit visual mode by pressing F1
- When in visual mode:
- Press Option+x to cut the current selection.
- Press Option+c to copy the current selection.
- Press Option+v to paste the last copied or cut buffer.
Line editing was done using the termcap library and not ncurses, as imposed by the subject.
Our shell is not entirely POSIX compliant but we did try to follow the POSIX guidelines as much as we could.
We learned a lot throughout these 4 months of hard work, and still have a lot of room for improvement. Code readibility, code structure, code maintainability…
Developed by : @aschoenh, @benjyskan, @mporzier, and @pscott.