Skip to content

TristanBilot/42sh

Repository files navigation

42sh

42sh was a team project made at EPITA in which we had to implement a POSIX shell from scratch using pure C. No memory leaks were allowed and we needed to implement by ourselves most of useful C functions. Our 42sh do not use standard builtins so we had to create the famous ones like echo, source, continue, break, exit, export...

Authors: Bilot Tristan | Delfau Nora | Salemi Enzar | Thambithurai Madushan

  • POSIX compliant
  • no memory leaks
  • no warnings/errors
  • tested on ArchLinux, Ubuntu, MacOS

Usage

Build the shell (3 ways)

1. ./build.sh
2. mkdir build && cd build && cmake . && make
3. cmake . && make

Run the shell

1. ./build/42sh
2. ./42sh (only if built with the #3 way)

Generate Doxygen documentations

1. ./build.sh doc         (this will build/rebuild the 42sh before)
2. cd build && make doc   (if the shell is already built)
3. ./documentation.sh     (if the shell is already built)
4. make doc               (if shell built with the 3rd way)

Read Doxygen documentaions

-- evince doc/latex/refman.pdf
-- cd doc/man/man3 && man ./[SOURCE FILE NAME].3
-- firefox doc/html/index.html

Run the python testsuite

1. ./build.sh check       (this will build/rebuild the 42sh before)
2. cd build && make check (if the shell is already built)
3. make check             (if shell built with the 3rd way)

Clean the project (3 ways)

1. ./clean.sh
2. cd build && make clean
3. make clean

Commands

Command substitution

echo $(ls -la && pwd)

Arithmetic substitution

echo $((2*33/2-2))
echo $((!3&&1 || 3))
echo $((~2- ~3 + ~1&& ~4/4-1))

Redirections and pipes

./42sh 2>/dev/null >/dev/null
tree . | ./42sh >> file
cat< test_suite.py

Variables and aliases

var=$(echo 42); echo $var
echo $RANDOM${UID}
alias ll="ls -l"; ll; unalias ll
export PWD="/bin"; export

Loops

for i in a b c d e; do echo "Hello, world !"; done
for i in {0..42}; do echo "current: $i"; done
while ! echo a | echo b | echo c; do echo toto; done
until echo a | echo b | echo c; do echo toto; done

Conditions

if cat README; then echo success; elif ls; then echo success; else echo failed; fi
if echo toto; then echo success; else echo failed; fi
case a in b | c | d ) hello & ;; esac

Binary operators

( a || ( ( b && c; ) || ls\n ); )

Signals and History

Key Signal
Ctrl+C
Ctrl+Z
Ctrl+L
Kill current process
Suspend curent process
Clear shell
Tab
Autocompletion
^
v
Browse history
<
>
Browse current command