Giter Site home page Giter Site logo

42_minishell's Introduction

new Topics to Study:

  • Machine Learning and LLM
  • VR/AR Interface for Meta Quest 3

About Me:

  • 👋 Hi, I’m Antonio Thomacelli
  • 👀 I’m interested in Full Cycle Development and DevOps
  • 💞️ I’m looking to collaborate on Kubernetes, HELM, Istio, or Go Projects ...
  • 📫 How to contact me [email protected]

🌱 Learning:

  • I’m currently learning C, Go, ReactJS and Software Architecture ...

📌 Pinned:

  • Projects pinned means, This is where I'm currently working!

42_minishell's People

Contributors

carlosrocha-dev avatar tonnytg avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

42_minishell's Issues

Create a database for variables

We need create a some way to store variables local or global for system

Command: set
Command: env

Local variables = only readable in shell level currently
Global variables = readable in shell level currently and in next levels

refactor main to exit when run command exit

What's happend?

When run command exit, command exit return status code 1 and infinite loop break only when status code is equal 1, different of 1 loop didn`t break.

What expected?
When run exit, infinite loop of main must broken loop

main return exit_code to caller

When execute exit -1 the main function must to return exit_code to first bash called minishell

./minishell << EOF
exit 1
EOF

echo $? // must be 1

./minishell << EOF
exit a
EOF

echo $? // must be 2

./minishell << EOF
exit -1
EOF

echo $? // must be 255

exit with no options

Commands need return:

  • CMD: exit 1 2 3

Must return: bash: exit: too many arguments
ERROR CODE: 127 or 1 ? Need check

  • CMD: exit a

Must return: bash: exit: a: numeric argument required
ERROR CODE: 2

  • CMD: exit 8

Must return: exit
ERROR CODE: 8

  • CMD: exit -2

Must return: exit
ERROR CODE: 254
NOTE: Mod of 255 to return 254 just like bash

Docs:
https://www.linuxdoc.org/LDP/abs/html/exitcodes.html

bug when press CTRL + D

What happen?
When press CTRL + D the minishell stay locked in infinite loop printing >

What expected?
When press CTRL + d only exit the program cleaning all struct and exit after

bug: empty command

When start minishell and press enter without command

  ==1105== 
  ==1105== HEAP SUMMARY:
  ==1105==     in use at exit: 1 bytes in 1 blocks
  ==1105==   total heap usage: 36 allocs, 35 frees, 5,236 bytes allocated
  ==1105== 
  ==1105== 1 bytes in 1 blocks are definitely lost in loss record 1 of 1
  ==1105==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==1105==    by 0x10B124: ft_strdup (in /app/minishell)
  ==1105==    by 0x109722: read_keyboard (input.c:40)
  ==1105==    by 0x10945B: minishell (main.c:46)
  ==1105==    by 0x109580: main (main.c:73)
  ==1105== 
  ==1105== LEAK SUMMARY:
  ==1105==    definitely lost: 1 bytes in 1 blocks
  ==1105==    indirectly lost: 0 bytes in 0 blocks
  ==1105==      possibly lost: 0 bytes in 0 blocks
  ==1105==    still reachable: 0 bytes in 0 blocks
  ==1105==         suppressed: 0 bytes in 0 blocks
  ==1105== 
  ==1105== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

export with no options

Ref: https://www.computerhope.com/unix/bash/export.htm

Definition of done:

The shell shall format the output, including the proper use of quoting, so that it is suitable for reinput to the shell
as commands that achieve the same exporting results, except:

    1. Read-only variables with values cannot be reset.

    2. Variables that were unset at the time they were output need not be reset to the unset state if a value is  assigned
       to  the  variable  between  the  time  the state was saved and the time at which the saved output is reinput to the
       shell.

   When no arguments are given, the results are unspecified. If a variable assignment precedes the command name of  export
   but that variable is not also listed as an operand of export, then that variable shall be set in the current shell exe‐
   cution environment after the completion of the export command, but it is unspecified whether that  variable  is  marked
   for export.

In interactive mode

Para encerrar essa Issue tem que ter feito as demais

ctrl-C displays a new prompt on a new line.

bug: when type wrong command, valgrind find errors

What's happend?
Execute a wrong command and in valgrind show this message

==1141== 1 errors in context 2 of 2:
==1141== Use of uninitialised value of size 8
==1141==    at 0x109665: execute_cmd (commands.c:25)
==1141==    by 0x10939D: minishell (main.c:57)
==1141==    by 0x10949D: main (main.c:80)
==1141==  Uninitialised value was created by a heap allocation
==1141==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1141==    by 0x109434: main (main.c:75)
==1141== 
==1141== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

What's expected?
only show message bash: COMMAND: command not found without leaks

Create a base to work with signals

We need a new function to call configuration for signals:

This new caller function need can possible to solve next issues of signals

ctrl-\ does nothing. #24
#24

ctrl-D exits the shell. #23
#23

Convert str to token

When execute command, the adapter receive char *arg but must be a list of words.
This can be solved convert this unique sentence of string to a matrix of strings. char *str to char **strgs for example.

Can be a Matrix, Linked list, Array ...

Example of standard commands strtok this command convert string to token

#include <stdio.h>
#include <string.h>

char *strtok_custom(char *str, const char *delim) {
static char *last = NULL;
char *token;

  // If str is not NULL, start from the beginning
  if (str != NULL)
      last = str;

  // If last is NULL, there are no more tokens
  if (last == NULL)
      return NULL;

  // Skip leading delimiters
  last += strspn(last, delim);

  // If last points to the end of the string, there are no more tokens
  if (*last == '\0')
      return NULL;

  // Find the end of the current token
  token = last;
  last = strpbrk(last, delim);

  if (last != NULL) {
      // If a delimiter is found, replace it with a null terminator
      *last = '\0';
      last++;
  }

  return token;

}

Prompt didn’t accept empty command and broke

What happen?

  • After press ENTER without no commands input in prompt, MiniShell broken segment fault

What expected?

  • Prompt understand signal of CTRL + C and make free in array of commands

Implement pipes

Implement pipes (| character). The output of each command in the pipeline is connected to the input of the next command via a pipe

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.