iShell is a Linux shell that I built from scratch!
It consists of a lexical analyzer and a syntactic analyzer.
The programs are super modular, both at function level and source code level!
iShell can handle external and built-in commands, input/output redirection, signals, and errors.
- Download or clone this project repository
- Open terminal and type
- To build everything, type
iShelland have fun!
- Write to
stdouta prompt consisting of a percent sign and a space.
- Read a line (that is, an array of characters) from
- Write the line (array of characters) to
stdout, and flush the
- Pass the line (array of characters) to your lexical analyzer to create
DynArrayobject containing tokens.
- Pass the
DynArrayobject containing tokens to your syntactic analyzer to create a command.
- Execute the command.
iShell does this repeatedly until the it reaches end-of-file of
- Accept an array of characters, and return a DynArray object containing tokens.
- From the user's point of view, a token is a word. More formally, from the user's point of view a token consists of a sequence of non-white-space characters that is separated from other tokens by white-space characters. Strings enclosed in double quotes (") form part or all of a single token.
- The lexical analyzer works for lines of any length.
- In other words, the lexical analyzer allows us to do something like:
- Accept a
DynArrayobject containing tokens, and return a command.
- The DynArray object containing tokens begins with an ordinary token, which is the command's name. It is an error for the DynArray object not to begin with an ordinary token. The command name token might be followed by tokens which are command-line arguments, tokens which indicate redirection of
stdin, and/or tokens which indicate redirection of
A demo looks like this:
External & Built-in Commands
iShell not only handles external commands but also deals with shell built-in commands!
||If environment variable
iShell handles redirection of
When the user types
Ctrl-c, Linux sends a
SIGINT signal to
iShell (parent) process and to its child process.
Here's a demo that tries to run
iShell handles each erroneous line
stderr and rejecting the line.
By the way, it is impossible for your input to cause
iShell to terminate abnormally. You can try!
iShell has no memory leaks (at least
meminfo reports say so)! Every
calloc has a corresponding