U bekijkt momenteel de Netherlands versie van de site.
Wilt u overschakelen naar uw lokale site?
13 MIN LEESTIJD

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.

Ontgrendel dit artikel en nog veel meer met
Je kunt genieten:
Geniet volledig van deze editie
Direct toegang tot 600+ titels
Duizenden oude edities
Geen contract of verplichting
ABONNEER NU
30 dagen proberen, dan gewoon €11,99 / maand. Op elk moment opzeggen. Alleen nieuwe abonnees.


Meer informatie
Pocketmags Plus
Pocketmags Plus

Dit artikel komt uit...


View Issues
Linux Format
January 2024
IN DE WINKEL BEKIJKEN

Andere artikelen in dit nummer


WELCOME
MEET THE TEAM
We’re trying to entice people to learn to
Fresh start
As we dive into 2024 and a whole
REGULARS AT A GLANCE
Newsdesk
THIS ISSUE: Valve console Steams ahead Foundations laid for HPSF Canonical cloud creation
High Performance Software Foundation announced
The HPSF is to inspire HPC innovation and “make life easier for high performance software developers”.
Canonical launches MicroCloud
The Ubuntu publisher releases new cloud software.
WHAT’S IN A NAME?
Italo Vignoli is one of the founders of
CLOSING THE DOOR
Joe Brockmeier is head of community, Percona. Another
Blender 4.0 released
Latest stable version has overhauled UI and improved support for OneAPI.
Foundation gets €1 million from Germany
Gnome recognised as public interest infrastructure.
Itanium heading for scrapheap
The end of an era: Will the Linux kernel drop support for ia64 architecture?
Distro watch
What’s behind the free software sofa?
DRIVER’S TEST
Faith Ekstrand is an engineering fellow at Collabora.
GETTING TOGETHER
Jon Masters is a kernel hacker who’s been
Kernel Watch
Jon Masters keeps up with all the latest happenings in the Linux kernel, so you don’t have to.
ONGOING DE VELOPMENT
There continue to be significant developments on the
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
WRITE TO US Do you have a burning
HotPicks
THE BEST NEW OPEN SOURCE SOFT WARE ON THE PL ANET
REVIEWS
Intel Core i9 14900K
Fast, powerful and a bit boring is not how to describe Jacob Ridley…
OSGeoLive 16.0
Uncharted no more – Nate Drake maps out the array of geospatial tools on offer in the specialist distro OSGeoLive.
GhostBSD 23.10.1
Roll over Slimer. Nate Drake explores the latest GhostBSD and finds that, like Casper, it’s extremely friendly and easy to manage.
Kubuntu 23.10
Nate Drake explores the lavish new Plasma desktop in the latest Kubuntu. Is this the greatest KDE-based distro to date?
Counter-Strike 2
It’s CS:GO Jim, but not as we know it, says Rich Stanton, as he takes the long-standing esport stalwart’s successor for a spin.
ROUNDUP
Live distributions
Michael Reed checks out five distros that you could carry around on your keychain to give you Linux goodness at a moment’s notice.
LEARN LINUX!
Finally had enough of your Windows PC? Nick Peers reveals how to fully road-test – then switch to – a user-friendly Linux distro.
Pi USER
Arm buys a slice of Pi
The deal effectively cements the Raspberry Pi to the Arm ISA for an undisclosed sum.
Pi OS Bookworm
Les Pounder has a Raspberry Pi 5 and isn’t afraid to use it, now that he has the latest Raspberry Pi OS.
Creality K1 Max
A big fan of fancy, Denise Bertacchi has taken to the K1’s bigger brother.
Take your Pi 5 to the next level!
Les Pounder has got his hands on a Raspberry Pi 5 and wants to show you how to get the best from it.
IN DEPTH
Tall Tails
Nate Drake explores how to configure the latest version of Tails for maximum security and convenience.
TUTORIALS
Safeguard your secrets
Shashank Sharma gets a taste for 007’s life by reading fiction and occasionally sending encrypted messages to his unsuspecting brother.
Dump your paper docs with perfect OCR
Nick Peers reveals how to extract editable text from images and printed materials with the help of optical character recognition software.
WordPress security, events and users
Michael Reed concludes his overview of setting up and maintaining a WordPress site with some finishing touches and a look at plugins.
Relive your BBC Basic days!
Turn your home system into a BBC Micro by following David Bolton’s advice to download BBC Basic and write programs just like it’s 1982.
Make your own pointand-click adventure
Nate Drake invites you to relive the glory days of Scumm-style point-and-click adventure games by creating your very own.
ADMINISTERIA
Massively improve your SSH login security
Passwords are so last century proclaims Stuart Burns! Using public keys and a couple of tweaks makes for a far more secure login.
Learning the way of the Docker
Docker is designed for an easy sysadmin life. Here are some top tips for using it.
Oxylabs
Mayank Sharma finds this proxy service to be a breath of fresh air.
Private Internet Access
A high-value VPN with a pile of interesting features that’s keeping the nefarious Mike Williams out of trouble.
No Ethernet, I expect you to die!
More stubborn than an anachronistic spy stereotype and just as reliable, Darien GrahamSmith uncrosses the network twisted pair.
CODING ACADEMY
Build a smart-home data application
Matt Holder investigates how to take data from an API and display it in a GUI for fun and possibly profit!
Chat
X
Pocketmags ondersteuning