Skip to content

Create a basic custom shell that mimics the functionality of a Linux shell — ALX software engineering program

Notifications You must be signed in to change notification settings

EL-OUARDY/simple_shell

Repository files navigation

ALX — Custom Simple Shell Project in C Language

Project Overview

This is a simple shell project developed as part of ALX software engineering program. The goal of this project is to create a basic shell that mimics the functionality of a Linux shell.

Requirements

Output

Unless specified otherwise, your program must have the exact same output as sh (/bin/sh) as well as the exact same error output. The only difference is when you print an error, the name of the program must be equivalent to your argv[0] (See below)
Example of error with sh:

$ echo "qwerty" | /bin/sh
/bin/sh: 1: qwerty: not found
$ echo "qwerty" | /bin/../bin/sh
/bin/../bin/sh: 1: qwerty: not found
$

Same error with your program hsh:

$ echo "qwerty" | ./hsh
./hsh: 1: qwerty: not found
$ echo "qwerty" | ./././hsh
./././hsh: 1: qwerty: not found
$

Testing

Your shell should work like this in interactive mode:

$ ./hsh
($) /bin/ls
hsh main.c shell.c
($)
($) exit
$

But also in non-interactive mode:

$ echo "/bin/ls" | ./hsh
hsh main.c shell.c test_ls_2
$
$ cat test_ls_2
/bin/ls
/bin/ls
$
$ cat test_ls_2 | ./hsh
hsh main.c shell.c test_ls_2
hsh main.c shell.c test_ls_2
$

Allowed functions and system calls

access / chdir / close / closedir / execve / exit / _exit / fflush / fork / free / getcwd / getline / getpid / isatty / kill / malloc / open / opendir / perror / read / readdir / signal / stat / lstat / fstat / strtok / wait / waitpid / wait3 / wait4 / write /

Compilation

Program will be compiled this way:

gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh

Steps to Implement

  1. Create a loop to continuously accept user commands.
  2. Parse the user input to identify the command and its arguments.
  3. Execute the command with execve() in a child process created using fork().
  4. Handle non fullpath command \
  5. Process built-in commands such as exit, cd, env ...etc
    ... MORE STEPS WILL BE ADDED AS WE PROGRESS IN THE PROJECT

Project File Structure:

  1. shell.h — header file that contains all used functions and custom struct types.
  2. main.c — contains the primary function of our shell, serving as the program's entry point and featuring the foundational code for our shell's operation.
  3. command.c — function to perform operations on the shell command.
  4. arguments.c — functions for handling and parsing command-line arguments passed to our custom shell.
  5. builtin.c — contains functions to handle builtin commands.
  6. strings.c — this file encompasses all the functions to deal with strings.
  7. lists.c — contains all function to manipulate linked lists.
  8. environment.c — functions for manage and interact with the environment variables, including setting, getting, or modifying environment settings.
  9. errors.c — handle error messages.
  10. cleanup.c — includes functions responsible for cleaning up resources, ensuring proper termination and avoiding memory leaks.
  11. _getline.c — custom implementation of the built-in getline function.
  12. _strtok.c — personalized version of the native strtok string tokenization function.

Team Members:

Hamza Daziahttps://github.com/HamzaDazai
Ouadia EL-Ouardyhttps://github.com/EL-OUARDY

About

Create a basic custom shell that mimics the functionality of a Linux shell — ALX software engineering program

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages