Pronounced as "michelle", a reference to The Beatles' song Michelle.
make # Build
./meeshell # Run
- Following are special tokens:
>
,>>
,>>>
,&
. The input is split into tokens by spaces, special tokens, or quoted strings. - When a special token is encountered it is added to the token list as a separate token, if it is not quoted.
&
token must be the last token in the input, otherwise an error is thrown.
- Prompt replaces
~
with the home directory of the user. - Input is read to a buffer of size 1024.
- Aliases are stored in
.meeshrc
file. - At the beginning of the program, .meeshrc file is read and aliases are stored in a hash map, see
dictionary.h
for implementation. - Aliases can be added with
alias key=value
syntax, and removed withalias key=""
syntax. - After an expression is matched with above syntax the rest of the line is ignored.
- Aliases can be overwritten.
- Aliases are expanded once, no recursive expansion.
- All the session aliases are written to .meeshrc file at the end of the program.
- Current Shell holds the name of parent process, if it is not a shell (for example logind, then its value is logind). Alternatives:
$SHELL
environment variable stores the login shell, which may not be the parent shell. - Number of processes shows the number of running processes spawned by the shell, except the dummy processes created for
>>>
. bello
output can be redirected and run in background.
cd
is a built-in command, changes the current working directory.
exit
is a built-in command, exits the shell.<Ctrl-D>
also exits the shell.<Ctrl-C>
does not exit the shell, prints a new line.
- All external commands are executed with
fork()
andexecv()
. Commands are first searched in the aliases, if not found, then in the PATH environment variable, it is assumed that it is an absolute/relative path. - Background processes are kept in
user->bg_pids
list. Number of processes inbello
is the length of this list. When a background process terminates, it is removed from the list, and reaped withwaitpid()
in a signal handler.
>
and>>
redirections are handled bydup2()
calls.>>>
redirection in background is handled by creating a dummy process, which waits for the command to finish, and then exits. Dummy processes are not included inbello
process count. Dummy process reads from a pipe, reverses the input, and writes to the file.
The project is implemented in OOP style: Main:
main.c
contains the main loop, and the signal handlers.
Classes:
tokenizer.c
contains the tokenizer implementation.dictionary.c
contains the hash map implementation.repl.c
contains the REPL implementation.user.c
contains the user object implementation.
Utilities:
utils.c
contains the utility functions, for executing commands, redirections, and user info. Please refer to header files for documentation.