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
.meeshrcfile. - At the beginning of the program, .meeshrc file is read and aliases are stored in a hash map, see
dictionary.hfor implementation. - Aliases can be added with
alias key=valuesyntax, 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:
$SHELLenvironment 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
>>>. bellooutput can be redirected and run in background.
cdis a built-in command, changes the current working directory.
exitis 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_pidslist. Number of processes inbellois 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 inbelloprocess count. Dummy process reads from a pipe, reverses the input, and writes to the file.
The project is implemented in OOP style: Main:
main.ccontains the main loop, and the signal handlers.
Classes:
tokenizer.ccontains the tokenizer implementation.dictionary.ccontains the hash map implementation.repl.ccontains the REPL implementation.user.ccontains the user object implementation.
Utilities:
utils.ccontains the utility functions, for executing commands, redirections, and user info. Please refer to header files for documentation.