Minishell

OchouatiOchouati
2 min read

Minishell is a project where you have to implement a program in C lang that do the basic functionalities of the Bash, and that's include handling pipes, redictions (<<, >>, < and >) environments variables and 7 of Built-in commads (echo, exit, unset, export, env, cd and pwd) and signals.

To complete the project we have divided the project to several tasks, and we have used Trello to track the progress of our task,

Parsing Part:

this part contains 4 sub parts:

Lexer

take the line and split it, and define its type (word, redirection, pipe, file, delimiter ...) and its state (general, between single quote or double quote..).

Syntax errors

search for syntax errors

Expander

expand the environments variables.

Joining

this is the last part of parsing where we remove the quotes and prepare the final command.

Exection

this part contains the built-in, redirections piping and execution (using the function execve function).

Builtins

cd: using chdir sys call function you can handle this one, handlig the errors is up to you !

pwd: also using getcwd sys call and you have to print it using printf or write.

echo: using printf

env: printing your env using printf or write

export-with-args: add a new arg to your env or replace one if already existed.

export-without-args: print the env + envs that doesn't have values..

unset: remove an env

exit: clean up and exit the program with last exit value if the number didn't specified.

Redirections

<<: herdoc, open a file and write in it, then if it's the last in use it as an input to your command

\>>: append, if the file already exist and has some content and the file is the last out ouput in it without removing the existing content.

\>: out if last out ouput in it but remove the existing content.

<: if it's the last in use it as an input to the command

0
Subscribe to my newsletter

Read articles from Ochouati directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ochouati
Ochouati