A lightweight Unix shell written in C. Nutshell supports built-in commands, external program execution, I/O redirection, background processes, and batch mode.
- Built-in commands —
cd,clr,dir,environ,echo,help,pause,quit - External commands — runs any program available on your system via
fork/execvp - I/O redirection —
<,>, and>>operators - Background execution — append
&to run a command without blocking the prompt - Batch mode — pass a file of commands as an argument
makeThe binary is placed in bin/nutshell.
To clean up:
make cleanInteractive mode:
./bin/nutshellBatch mode:
./bin/nutshell commands.txt| Command | Description |
|---|---|
cd [dir] |
Change directory (no argument prints current directory) |
clr |
Clear the screen |
dir [dir] |
List directory contents (ls -al) |
environ |
Print all environment variables |
echo [text] |
Print text to stdout |
help |
Display the user manual via more |
pause |
Pause until Enter is pressed |
quit |
Exit the shell |
Internal commands are built directly into the shell — they run instantly without spawning a new process. Just type the command name at the prompt:
/home/user> echo Hello World
Hello World
/home/user> cd /tmp
/tmp>
/tmp> dir
total 0
drwxrwxrwt ...
These are always available regardless of your PATH.
External commands are any programs installed on your system. Nutshell finds them via your PATH environment variable, forks a child process, and runs them with execvp. Use them exactly as you would in any other shell:
/home/user> ls -la
/home/user> grep "foo" file.txt
/home/user> python3 script.py
/home/user> gcc main.c -o main
If a command isn't found, you'll see:
nutshell: command not found: badcommand
The key difference: internal commands run inside the shell process (so cd can actually change the shell's directory), while external commands run in a separate child process and can't affect the shell's own state.
# Redirect input
sort < names.txt
# Redirect output (overwrite)
ls > files.txt
# Redirect output (append)
echo done >> log.txt
# Combined
sort < unsorted.txt > sorted.txtThe dir, environ, echo, and help built-ins support output redirection.
sleep 30 &
find / -name "*.log" &The shell prints the background process PID and returns the prompt immediately.
nutshell/
├── src/
│ ├── nutshell.c # Main entry point and shell loop
│ ├── nutshell.h # Header — structs, constants, prototypes
│ └── utility.c # Built-in commands, parsing, execution
├── bin/ # Compiled binary (generated by make)
├── manual/
│ └── readme.txt # Full user manual (viewed via the help command)
└── makefile
- GCC
- POSIX-compliant OS (Linux or macOS)