Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

shell_with_c

A minimal unix shell written in C, built in 2023 to learn how shells actually work under the hood - process creation, program exectution, and terminal I/O without any libraries beyond libc.

What it does

  • REPL loop - reads a line, tokenizes it, executes, repeats
  • Tokenization - splits input on whitespace with a growable token buffer (no fixed argv limit)
  • Program exectuion - fork() + execvp() with a proper wait/exit-status handling in the parent
  • Built-ins - exit handled in process (no fork)
  • Error handling - allocation failures and exec errors reported with colored output

Build & run

gcc shell.c -o dash
./dash
> ls
> echo "hello world"
> exit

What I learnt

The core insight: a shell is just a loop around fork/exec/wait. The subtle parts are memory ownership of the token buffers, distinguishing built-ins (which must run in the shell's own process) from external commands, and resizing input buffers safely as the user types arbitrarily long lines.

About

A basic shell made using C

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages