DEV Community

Abhishek Keshri
Abhishek Keshri

Posted on

CShell - A bash alternative written in 500 lines of C β›΅πŸš

cshell

Not a seashell β›΅πŸš

What is this

cshell is an alternative to the standard sh shell written entirely in c and all in a single file within ~500 LOC.

It supports pipes, redirections, history, and more. Comes with a customized prompt.

Inspiration

Most Operating Systems classes have a project for creating a shell. I never got to around to do that.
This is my shot at creating my own shell.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed the latest version of gcc, make

Getting cshell

To install cshell, follow these steps:



git clone https://github.com/2kabhishek/cshell
cd cshell
make cshell


Enter fullscreen mode Exit fullscreen mode

Using cshell

You can link the cshell executable to your $PATH or just run it from the command line.



./cshell


Enter fullscreen mode Exit fullscreen mode

This will start the shell and display the a help message along with the prompt.
You can use it like any other shell.

How it was built

cshell was built using c

Challenges faced

  • Struggled somewhat in the begining to handle signals, but eventually got it working.

What I learned

  • Learned a lot about c and it's different syscalls.
  • Understood the internal workings pipes and redirections.

What's next

Clean up the code and make it more readable, add more features, and make it more robust.

Hit the ⭐ button if you found this useful.

More Info

Source | Website

Top comments (2)

Collapse
 
miguelmj profile image
MiguelMJ

I remember doing my own shell in C, it's one of the coolest projects I made in my grade. BTW, the website link goes 404.
Cool project, anyways! I recommend you checking out the ANSI codes for displaying color in a console (at least for the ones that support it (most of them in Linux) )

Collapse
 
2kabhishek profile image
Abhishek Keshri

I've been thinking about adding ansi colors to prompt, will add it next time I revisit this. And for the site issue, I'm actually using one of my template repos (github.com/2kabhishek/BareMinimum) for setting up the repo so the link is just something I need to enable on GitHub pages.

Thanks a lot for your suggestions!