CMAKE
Write a Linux shell from scratch
Never one to shy away from the difficult, Ferenc Deak takes us by the hand and helps us code a shell – from scratch.
Part One!
Don’t miss next issue, subscribe on page 16!
OUR EXPERT
Ferenc Deak wanted to use Malbolge to create a Linux shell, but after several days in hell, he quickly came to his senses and continued the project in C++. Not that there is a huge difference…
QUICK TIP
Explore the code and build it yourself to gain a wider perspective on how everything comes together: https://github.com/fritzone/lxf-shell.
In the Linux ecosystem, the shell is a vital component – a command-line interface (CLI) program, enabling users to interact with the underlying operating system through textbased commands. It acts as a bridge, facilitating communication between users and the core components of the operating system, which manage hardware resources and system services. This series of tutorials embarks on a fascinating journey on how to write a Linux shell from the ground up, offering readers a unique opportunity to explore the inner workings of such a fundamental tool.
While shells can be written in scripting languages such as Python and Ruby, we’re taking a more low-level approach for a modern spin. This article builds on the foundation of Chris Brown’s article in LXF149, providing gentle guidance into programming a shell, with the twist of a fresh perspective. Switching from plain C to C++, we’re using the CMake build system to streamline development and manage dependencies.
Due to space constraints, we’re printing only the essential introductory code snippets. Subsequently, we’ll reference different sections for a comprehensive understanding. To access the complete code for this shell, please visit https://github.com/fritzone/lxf-shell. We strongly encourage you to explore the code and build it yourself to gain a better perspective of how everything comes together (the code there has also comments that were removed here for the purpose of keeping the size of the tutorial manageable).
With all this in mind, we can embark on the perilous journey of writing a Linux shell. From scratch. The main reason is not that the world needs another shell, as there is already a plethora of them, but more to provide an opportunity to learn about the lower-level Linux system internals, to give you the chance to understand how stuff works behind the scenes, and while doing so, provide you with a basic introduction to build management with CMake (see boxout, page 93), and to give a brief introduction to C++ as the choice of programming language of this guide.