myshell is a simple light weight, Unix command line shell with some fun and interesting feature written from scratch in C, and using a WSL2/Ubuntu environment. Myshell was built with a focus on practicing the fundamentals of systems programming as a craft, it adhering to compilation standards (-Wall -Wextra -Werror -pedantic).
The shell was developed progressing through iterations, from a basic REPL(read, eval, print Loop) common for modern programming languages to more robust process orchestration:
- Core Infrastructure Components & REPL:
- A continuous read, eval, print Loop using the GNU Readline.
- Token parsing with
strtok()to split the command line input into argument vectors (char **args). - For the external binary execution with POSIX system calls, the following was used:
fork()for process creation andexecvp()for binary replacement.
- Built in Commands:
cd [path]: Changing the working directory usingchdir().exit: Terminating the shell efficiently.history: Displaying an indexed list of the commands entered during that current session using Readline'shistory_list().
- I/O Redirection (
>,<):
- Output redirection (
>) opens or can create files withopen(), and truncating existing content, and then hooks them withdup2(fd, STDOUT_FILENO)inside that child process. - Input redirection (
<) hooking files toSTDIN_FILENOso they can be read.
- Command Piping (
|):
- For implementing inter process communication (IPC) using a
pipe()system call. - It's able to spawns two child processes, and bridging the output of the left command to the standard input of the right command with file descriptor duplication and proper clean up of any unused pipe ends.
- GNU Readline & Advanced UX:
- Integrated
libreadline-devthat supports cursor navigation (left/right arrow movement) and command history cycling using (up/down arrows). - Recursive directory completion engine (
opendir,readdir,closedir) mapped to the Readline menu completion hook, enabling a basic type of interactive search and tab selection.
Because thia type of project enforced -Werror (treating all the compiler warnings as errors), minor syntax or code hygiene oversights did at times halt the build process.
A notable instance occurred while implementating the recursive directory tab completion feature:
- The Error: GCC threw a compilation failure:
main.c: In function ‘recursive_file_generator’:
main.c:190:17: error: unused variable ‘st’ [-Werror=unused-variable]
190 | struct stat st;
| ^~
cc1: all warnings being treated as errors
- The Fix: The
struct stat st;variable was declared for previous file status checks that were now being handled with name matching logic instead. Satisfying strict compiler checks, just needed the unused variable to be stripped from therecursive_file_generator, allowingmaketo compilemyshellsuccessfully. Also other unused parameters likeendin the custom completion hooks were explicitly silenced using(void)end;.
Install the required development toolchains, Readline headers, and optional utility packages in your WSL2 Ubuntu terminal:
sudo apt update && sudo apt install build-essential libreadline-dev poppler-utils -y
- Clone or navigate to the repository directory.
- Compile the project using GNU Make:
make
- Launch your custom shell:
./myshell
To help explain the core systems concepts used in this project, check out our reference guides:
- Unix Systems Guide: Deep dive into POSIX syscalls, process spawning (
fork/execvp), file descriptor redirection (dup2), and IPC pipes. - C Programming Guide: Reference notes on memory safety, string tokenization, and pointer arithmetic.
myshell supports text extraction from a PDF documents using standard Unix pipelines combined with poppler-utils (pdftotext).
poppler-utils installation: sudo apt update && sudo apt install poppler-utils -y
Print extracted text to standard output (acting as a filter):
pdftotext document.pdf -
Searching for conecpt or keywords inside the PDF can be done with using a pipe:
pdftotext document.pdf - | grep "keyword"
To extract and save text to a new file type use the follwoing
pdftotext document.pdf extracted_output.txt