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

Alex Xander picture Alex Xander · Sep 30, 2009 · Viewed 36.4k times · Source

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.

Answer

Supertux picture Supertux · Sep 30, 2009

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.