__ __ ___ __ / // /|__ \ _____/ /_ / // /___/ // ___/ __ \ /__ __/ __/(__ ) / / / /_/ /____/____/_/ /_/
42sh is a POSIX-oriented Unix shell written in C99.
The project is built around a classic shell pipeline: input handling, lexing, parsing, AST execution, expansions, redirections, and process management. The implementation is split into focused modules and backed by both functional and unit tests.
- Input from standard input, script file, or inline command with
-c - Parsing support for command lists, pipelines,
&&/||, negation, subshells, blocks,if,case,for,while,until, and function declarations - Builtins:
cd,echo,true,false,export,unset,exit,break,continue,. - Variable expansion, special parameters (
$?,$$,$#,$@,$*, positional parameters), and command substitution with$(...) - Redirections including
>,>>,>|,<,<>,>&, and<& - Autotools-based build,
clang-formatchecks, and CI workflows for build, tests, coverage, and forbidden-function scanning
| Path | Role |
|---|---|
42sh/ |
Main project directory |
42sh/src/ |
Shell source code |
42sh/src/lexer/ |
Input backend and lexer |
42sh/src/parser/ |
Grammar and AST construction |
42sh/src/execution/ |
Runtime, expansions, variables, functions |
42sh/src/builtins/ |
Builtin implementations |
42sh/src/redirection/ |
Redirection handling |
42sh/src/pipe/ |
Pipeline execution |
42sh/src/utils/ |
Shared helpers and data structures |
42sh/tests/functionnal/ |
Python functional test suite |
42sh/tests/units/ |
Criterion-based unit tests |
.github/workflows/ |
CI configuration |
42sh.pdf |
Project documentation / report |
Doxyfile |
Doxygen configuration |
Build:
- C compiler with C99 support
makeautoconfautomakeautoconf-archivelibtoolpkg-config
Tests and coverage:
- Python 3
pytest- Criterion
gcovr
Example installation on Debian or Ubuntu:
sudo apt-get update
sudo apt-get install -y \
autoconf automake autoconf-archive libtool pkg-config \
python3 python3-pytest gcovr libcriterion-devcd 42sh
autoreconf -fi
./configure CFLAGS="-std=c99 -pedantic -Werror -Wall -Wextra -Wvla"
make -jThe binary is generated at 42sh/src/42sh.
# Interactive mode
./42sh/src/42sh
# Execute a script
./42sh/src/42sh ./script.sh
# Execute inline code
./42sh/src/42sh -c 'echo "42sh is running"'
# Pretty-print the AST instead of executing
./42sh/src/42sh -p -c 'echo hello | cat'
# Enable debug logging
./42sh/src/42sh -l -c 'echo hello'Run the functional suite through the project entrypoint:
cd 42sh
BIN_PATH="$(pwd)/src/42sh" OUTPUT_FILE="$(pwd)/out" make check
cat outRun functional tests together with unit coverage flow:
cd 42sh
BIN_PATH="$(pwd)/src/42sh" OUTPUT_FILE="$(pwd)/out" COVERAGE=yes make checkRun the functional tests directly with pytest:
cd 42sh
BIN_PATH="$(pwd)/src/42sh" pytest -q tests/functionnalGenerate coverage-oriented build artifacts explicitly:
cd 42sh
make coverage BIN="$(pwd)/src/42sh"- The project is built with strict warnings enabled:
-Werror -Wall -Wextra -Wvla - Formatting in CI is checked with
clang-format --dry-run --Werror make checkdelegates totests/check.py, which can write the success rate toOUTPUT_FILE- API documentation can be generated with:
doxygen DoxyfileSelected references for shell behavior, standards, implementation details, tooling, and project workflow.
- Berkeley Software Distribution
- POSIX
- IEEE Computer Society
- The Open Group Base Specifications Issue 7, 2018 Edition
- Shell Command Language
- Shell Grammar Rules
- Bash POSIX Mode
- GNU C Library: Implementing a Shell
- Thompson shell
- Almquist shell / dash
- shell.multun.net
- Recursive descent parser
- GNU Bash Manual
- Zsh Documentation
- KornShell Documentation
- tcsh
- Autotools tutorial (EPITA)
- GNU Autoconf Manual
- GNU Automake Manual
- GNU Libtool Manual
- Git
- Learn Git Branching
- GitLab Repository Mirroring
- GitLab CI/CD
- Doxygen
- Crafting Interpreters
- Agile Software Development
- Extreme Programming Roadmap
- Agile Alliance Subway Map to Agile Practices
- Software Craftsmanship Manifesto
This repository is distributed under the MIT license. See LICENSE.
Deep Thought informs the researchers that it will design a second and greater computer, incorporating living beings as part of its computational matrix, to tell them what the question is. That computer was called Earth and was so big that it was often mistaken for a planet. The researchers themselves took the apparent form of mice to run the program. The question was lost, five minutes before it was to have been produced, due to the Vogons demolition of the Earth, supposedly to build a hyperspace bypass. Later in the series, it is revealed that the Vogons had been hired to destroy the Earth by a consortium of philosophers and psychiatrists who feared for the loss of their jobs when the meaning of life became common knowledge.
Douglas Adams
Douglas Adams was asked many times during his career why he chose the number "forty-two". Many theories were proposed, but he rejected them all. On November 3rd, 1993, he gave an answer on alt.fan.douglas-adams:
The answer to this is very simple. It was a joke. It had to be a number, an ordinary, smallish number, and I chose that one. Binary representations, base thirteen, Tibetan monks are all complete nonsense. I sat at my desk, stared into the garden and thought "42 will do". I typed it out. End of story.