Giter Club home page Giter Club logo

linux_simple_shell's Introduction

Description

The simple_shell project is an attempt to replicate the behavior of the Linux sh shell. I have invited my friend to collaborate on this project with me as a second pair of eyes, to help identify potential flaws and suggest improvements. This project is also designed with the purpose of assisting beginer Linux developers in understanding the underlying processes and workings of the Linux system, as well as getting them familiar with some concepts in the C programming language.

  • Emulating sh Shell: Our shell aims to mimic the behavior of the sh shell, both in terms of output and error handling.
  • Learning Process: During this project, we delved into:
    • Understanding the workflow of a command-line interpreter.
    • Learning about process IDs (pid) and parent process IDs (ppid).
    • Managing processes and manipulating the environment.
    • Distinguishing between functions and system calls.
    • Creating new processes and executing commands with execve.
    • Handling PATH variables.
  • Code Quality: strong emphasis was placed on writing beautiful code following the Betty style guide and most importantly avoiding memory leaks.

Usage

First, you have to clone this repo $git clone https://github.com/rohteemie/simple_shell.git

Compile

gcc -Wall -Werror -Wextra -pedantic *.c -o executable_filename

Execute: see more in examples

Interactive mode:
$ ./hsh
./hsh$ [put_commands and_arguments]

Non-interactive mode
$ echo "[put_commands and_arguments]" | ./hsh

Built-ins

  • exit & exit(status)
    • env
    • setenv & unsetenv

Examples

1. Absolute path commands
- non interactive 

```bash
$ echo "/bin/pwd" | ./hsh
$ /home/rohteemie/simple_shell
```

- interactive mode 

``` bash
$ ./hsh
./hsh$ /bin/echo hello world
helo world
./hsh$ exit
$
```

2. short command
- non interactive 

```bash
$ echo "pwd" | ./hsh
$ /home/rohteemie/simple_shell
```

- interactive mode
``` bash
$ ./hsh
./hsh$ echo hello world
helo world
./hsh$ exit
$
```

3. built-ins
- non interactive
```bash
$ echo "exit" | ./hsh
$ echo $?
0
```

- interactive mode
``` bash
$ ./hsh
./hsh$ exit 98
$ echo $?
98
```

**Some error output**
``` bash
$ ./hsh
./hsh$ ls /non_existing_folder
ls: cannot access '/non_existing_folder': No such file or directory
./hsh$ exit
$ echo $?
2
```

``` bash
$ echo "non_valid_command" | ./hsh
./hsh: 1: non_valid_command: not found
$ echo $?
127
```

Project files

| File        | Description |
| ----------- | ----------- |
| AUTHORS     | File with names of the owners and authors of this project |
| Readme.md   | Nutshell description of simple_shell project |
| aux_funs.c  | Auxiliar functions <br> **signal_exit:** handler for SIGINT signals <br> **_calloc:** allocate memory and fills it with zeros
| built-ins.c | Built-ins functions: <br> **check_word:** evalute alpha chars in string <br> **exit_built_in:** stop execution of shell <br> **env_built_in:** prints environment variables |
| core_funs.c | Heart of simple_shell <br> **check_builtin:** check if first argument is a built-int <br> **not_found_error:** handler for print error when command is not found <br> **simple_exec:** decision flow for command execution|
| path_funs.c | Function to check command in path <br> **_getenv:** search variable in environment vars <br> **cmd_path:** concat first argument with PATH dirs |
| shell.h     | Header file <br> **All includes** <br> **All prototypes** <br> **Definition of struct params** |
| simple_shell.c | Initialize the simple_shell execution: <br> **test:** <br> Remove \n last char readed with getline <br> Tokenize and save in argv all arguments readed <br> Calls simple_exec <br> **main:** <br> Initialize params struct vars <br> Set signal listenes <br> Print prompt (interactive mode) <br> Read arguments with getline <br> Handle CTRL + D to stop execution|
| string_funs.c  | First string functions file <br> **_strcat:** concat string (no malloc) <br> **_strlen:** get length of string <br> **rev_string:** reverse a string <br> **_itoa:** convert int to string <br> **_strcmp:** compare two strings |
| string_funs2.c  | Second string functions file <br> **_strchr:** search char in string <br> **_strcpy:** copy string in other one <br> **str_concat:** concat string (malloc) <br> **_atoi:** convert string num, to int|

Full documentation

For more info about this project you can run the man page:

`$ ./man_1_simple_shell.3`

Authors

linux_simple_shell's People

Contributors

rohteemie avatar slomon80 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.