Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement my own basic unix shell in C?

Tags:

I'm a newbie to process and thread management. My Shell should understand PATH environment variable. It can be set and modified. It runs in two ways -interactive & batch mode. Shell is capable of taking more than one job like ls;ps;wc file;cal. I want to get my hands dirty on signals too. So I should handle ^K , ^c as well.

I know I will have to use execs, forks and pipes but just can't get started.

like image 709
Alex Xander Avatar asked Sep 30 '09 18:09

Alex Xander


People also ask

Is shell script written in C?

C shell's scripting syntax is modeled after the C language in some aspects. Small programs can be created by writing scripts using the C shell syntax. The Bourne shell is also an option to create Unix scripts but if you are reading this book you probably decided the C shell fits your requirements better.


1 Answers

All the unix shells are open-source - so a good place to start may be to read the code.

If you're looking for a good starter article on the subject try Writing Your Own Shell from the Linux Gazette.

Another good starting point is to take a look at the source code of mini-shell just because its one of the smallest to get your head round.

like image 54
Supertux Avatar answered Nov 08 '22 20:11

Supertux