Building MythSh: Crafting a Custom Unix Shell in C
I started building this project MythSh around September of 2025. Back then I was getting my hands dirty with Linux, operating systems, and understanding the low-level stuff. I was trying hard to be an 'engineer', trying to understand how everything worked under the hood. I had installed Ubuntu a month earlier and was getting used to the rather 'intimidating' terminal.
I was watching creators like 'Typecraft' and 'ThePrimeTime'. I remember Prime saying that if you wanted to become a better engineer, you should build something that you use every day. I came across a GitHub repo called 'Build Your Own X' which taught how one can build tools from scratch. Although I barely used the repo itself. I relied a little on AI in the beginning to understand how to get started.
It was wonderful understanding how system calls work. I had to build a parser that parsed my command into something the shell could execute. I was really fascinated to know how the shell itself executed as a process and how every external command entered would be executed in a child process created using fork()[1], which would then call execvp()[2]. We were being taught about these functions in our Operating Systems lab and here I was using them to actually build something.
It was enriching to learn about binaries and how they are executed by the shell. A very intriguing fact that I came to know while building it was that there was no cd[3] binary. It had to be implemented using system calls in C like chdir()[4] because changing directories has to affect the shell process itself. I also used getcwd()[5] to retrieve the shell's current working directory.
This was mostly how I built my shell. I actually wanted to name it 'Posh', but someone had already claimed that name. So I named it MythSh, which means 'mythical shell'.
Here is the link to the repo: https://github.com/adityapaul26/mythSh
[*] Footnotes & Explanations
- [1]
fork()creates a new child process by duplicating the current process. The parent and child continue executing independently from the instruction immediately following thefork()call. - [2]
execvp()replaces the current process with a new program. If the call succeeds, the original program is completely replaced and execution continues in the new program. - [3]Unlike commands such as
lsorcat,cdis not a standalone executable. It is a shell built-in because changing directories has to affect the shell process itself. - [4]
chdir()is a system call that changes the current working directory of the calling process. - [5]
getcwd()returns the absolute path of the current working directory.