Authors : KK, Adi, Alayna, Sumithra, Siddhartha
- Introduction
- From the ground up
- Genesis
- All about psh
- How you can run psh locally ?
- Benchmarks
- Experience
- Fun stuff
- References
- What made us choose this project ?
- As computer science students, we work with shells on a daily basis. Hence, building a shell from scratch was a great opportunity for us to explore its inside workings while tweaking it to match our custom needs.
It is a part of Tilde 3.0 HSP PESU-ECC's summer mentoring program: where 5 students developed this project under the guidance of 4 mentors. Under this program, we have developed psh, a custom POSIX-like compliant shell. It is implemented in C and aims to achieve all features of POSIX compliance while incorporating other features that set it apart
- Here is some background info you might require before diving into our project...
-
A shell is an cli interface that acts as an intermediary between a user and an operating system's kernel
-
Instead of using a graphical interface with buttons and menus, you type commands into the shell to control your system, like managing files or running programs.
-
Examples : bash, zsh, fish
POSIX is a family of standards, specified by the IEEE, to clarify and make uniform the application programming interfaces provided by Unix operating systems. POSIX compliancy implies your shell/shell utility can be ported anywhere across wide range of UNIX (derivatives)
So here's what exactly happens when you type a command in a shell, lets you want to execute a command call it 'X' so when you type it in the shell and hit enter. Your shell first checks whether the 'X' is an shell-builtin or a shell executable..
Whats a shell builtin ?
- It is a command or a function, called from a shell, that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute. Shell builtins work significantly faster than external programs, because there is no program loading overhead
Whats a shell executable ?
- These are commands stored in
/usr/bin/
or/usr/local/bin
How we started with psh ?
- Firstly we implemented a REPL algorithm which is basically an infinite while loop, awaiting user response for further commands.
├── bin
│ ├── builtin.o
│ ├── execute.o
│ ├── helpers.o
│ ├── main.o
│ └── psh
├── Makefile
├── README.md
├── script.sh
└── src
├── builtin.c
├── builtin.h
├── colors.h
├── execute.c
├── helpers.c
├── main.c
└── psh.h
-
We have 2 set of commands
- shell builtin :
cd
,exit
,echo
,type
,pwd
,fc
,export
,read
,alias
,unalias
- external :
ls
,lsblk
,ssh
,file
,script
- shell builtin :
- Script mode
- Syntax highlighting
- Signal handling
- Arrow keys
- Auto complete
- Globbing
git clone https://github.com/homebrew-ec-foss/psh
cd psh
make run
It was an overall fUn experience, learning fundamental concepts of os and understanding how shell works 🤯.
We also had a tough time debugging C code as we kept running into segmentation faults, as well as learnt how to use gdb
to get rid of segmentation faults. We learnt how to handle memory leaks and dynamic memory allocation in a much more efficient manner for a large codebase. Resolving merge conflicts was a new and slightly tedious experience.
Our mentors gave us some wonderful suggestions and feedback as to how to go about making this project. Their support has been instrumental. Tejas screaming was music to our ears 🥺