Giter Club home page Giter Club logo

42sh's Introduction

42sh

Bash-like shell It's a command-line interpreter

Features

  • Prompt with line edition
  • Builtins alias, bg, cd, echo, exit, export, fg, hash, jobs, set, source, test, type, unalias, unset
  • Executing simple commands
  • Execute in background &
  • Redirection >, >>, < and |
  • Heredoc <<
  • Logical operands && and ||
  • Separator ;
  • Inhibitors ", ' and \
  • Environment and local variables $VAR or ${VAR}
  • Command substitution $(CMD)
  • Dynamical autocompletion
  • History (saved in ~/.42sh_history)
  • PS1 environment variable to custom shell prompt (wiki)

Installation

$>  git clone https://github.com/tcollard/42sh.git
$>  cd 42sh && make
$>  ./42sh

Rules make

  • make compilation of binary executable
  • make clean delete all .o files
  • make fclean delete all .o files and ./42sh
  • make re do fclean and make

Shell

History

Commands Functions
!! Last command in history
!word Look for the last command starting by word
![-]number Look for the command at index number, - define that the search starts from the end

Alias

Commands Functions
alias List all the current aliases set
alias [name[=value] ...] Sets an alias for name so it replaces as value internally
unalias [-a] name [name ...] Remove the name arguments of the alias table. -a removes all aliases

Hash table

Commands Functions
hash List hash table contents
hash -r Clear the hash table

Job control

Commands Functions
jobs [n] List all the current running jobs, n specify the job you want (the form is in job id form or it can be a numerical value)
fg [n] Bring the specified job to foreground
bg [n] Bring the specified job to background

All of our shell functionalities are in Posix norm.

Authors

Name Mail Github
Gwennaël Guichard [email protected] https://github.com/gguichard
Franck Werner [email protected] https://github.com/FranckRJ
Jonas Cohen [email protected] https://github.com/jocohen
Thibault Collard [email protected] https://github.com/tcollard

42sh's People

Contributors

gguichard avatar franckrj avatar tcollard avatar jocohen avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

gguichard moezes

42sh's Issues

Probleme AST PIPE

Lorsque je rentre la commande "ls | > ok | > test" l'AST suivant est généré :

           "|"
           /  \
        "ls"  "|"
               /
           "> ok"
             /
        "> test"

alors que ça devrait plus correspondre à quelque chose comme :

            "|"
           /   \
        "ls"    \
                "|"
                / \
          "> ok"  "> test"

SEGV HISTORY

Quand tu lances 42sh et qu'il n'y a eu aucune commande.
Si on appuie sur la fleche du bas il y a un segv.

Voila la trace de fsanitize si ca peut aider:

prompt> AddressSanitizer:DEADLYSIGNAL

==68400==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000100fa23a8 bp 0x7ffeeec71660 sp 0x7ffeeec71640 T0)
==68400==The signal is caused by a WRITE memory access.
==68400==Hint: address points to the zero page.
#0 0x100fa23a7 in fill_input_buffer (debug:x86_64+0x1000143a7)
#1 0x100fa227c in load_entry_in_cmdline (debug:x86_64+0x10001427c)
#2 0x100fa232c in handle_history_next (debug:x86_64+0x10001432c)
#3 0x100fa0c6e in handle_sequence (debug:x86_64+0x100012c6e)
#4 0x100fa026a in process_input (debug:x86_64+0x10001226a)
#5 0x100fa020c in read_input (debug:x86_64+0x10001220c)
#6 0x100f9f69d in read_full_input (debug:x86_64+0x10001169d)
#7 0x100f9f5b6 in read_cmdline (debug:x86_64+0x1000115b6)
#8 0x100f9365e in main (debug:x86_64+0x10000565e)
#9 0x7fff60f37ed8 in start (libdyld.dylib:x86_64+0x16ed8)

pointer being freed was not allocated

La commande en question (deux doubles quotes sans rien a l'interieur) : ""

`=================================================================
==16747==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000001bd0 at pc 0x00010e50faa0 bp 0x7ffee17501f0 sp 0x7ffee17501e8
READ of size 8 at 0x602000001bd0 thread T0
#0 0x10e50fa9f in inhib_expand_tab inhibitor.c:150
#1 0x10e4bd13e in analyzer analyzer.c:89
#2 0x10e4b29b2 in lexer_parser main.c:35
#3 0x10e4b2f68 in main main.c:65
#4 0x7fff7d4573d4 in start (libdyld.dylib:x86_64+0x163d4)

0x602000001bd0 is located 0 bytes inside of 16-byte region [0x602000001bd0,0x602000001be0)
freed by thread T0 here:
#0 0x10e5b520d in wrap_free (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x5c20d)
#1 0x10e4b1b6c in ft_strtab_free (42sh:x86_64+0x100004b6c)
#2 0x10e50f238 in delete_line_tab inhibitor.c:121
#3 0x10e50fc15 in inhib_expand_tab inhibitor.c:154
#4 0x10e4bd13e in analyzer analyzer.c:89
#5 0x10e4b29b2 in lexer_parser main.c:35
#6 0x10e4b2f68 in main main.c:65
#7 0x7fff7d4573d4 in start (libdyld.dylib:x86_64+0x163d4)

previously allocated by thread T0 here:
#0 0x10e5b5053 in wrap_malloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x5c053)
#1 0x10e511a03 in create_new_input inhibitor_tools.c:78
#2 0x10e50f963 in inhib_expand_tab inhibitor.c:147
#3 0x10e4bd13e in analyzer analyzer.c:89
#4 0x10e4b29b2 in lexer_parser main.c:35
#5 0x10e4b2f68 in main main.c:65
#6 0x7fff7d4573d4 in start (libdyld.dylib:x86_64+0x163d4)`

Probleme d'analyse syntaxique

La commande "1>" provoque un segfault au niveau de l'analyse syntaxique (token_analyzer.c).

Voici la trace fsanitize depuis master :

AddressSanitizer:DEADLYSIGNAL

==82974==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000108496abe bp 0x7ffee77732f0 sp 0x7ffee7773140 T0)
==82974==The signal is caused by a READ memory access.
==82974==Hint: address points to the zero page.
#0 0x108496abd in token_analyser token_analyzer.c:60
#1 0x1084b900c in read_complete_command cmdline.c:98
#2 0x1084b872b in read_cmdline cmdline.c:114
#3 0x10848fd9c in main main.c:50
#4 0x7fff7d4573d4 in start (libdyld.dylib:x86_64+0x163d4)

==82974==Register values:
rax = 0x0000000000000000 rbx = 0x00007ffee7773180 rcx = 0x0000100000000000 rdx = 0x00007ffee7773160
rdi = 0x0000100000000000 rsi = 0x00001fffdceee62c rbp = 0x00007ffee77732f0 rsp = 0x00007ffee7773140
r8 = 0x0000200000000000 r9 = 0x00000fffffffffff r10 = 0x0000000000000000 r11 = 0xffffffffffffffff
r12 = 0x0000000000000000 r13 = 0x0000000000000000 r14 = 0x00001fffdceee664 r15 = 0x0000000000000004
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV token_analyzer.c:60 in token_analyser
==82974==ABORTING
Abort trap: 6

Mauvaise generation du redirect_inf

Lorsque je tape la commande "ls >> ok" l'attribut "lopt_fd" de la structure est defini a la valeur FD_AMPERSAND (-3) alors qu'il devrait etre a FD_DEFAULT (-2).

Probleme AST

Avec la commande ls | cat << EOF
le heredoc se trouve tout en haut de l'arbre alors qu'il devrait se trouver sur la droite du pipe, avec cat.

ctrl-c on ls -lR /

Quand on lance ls -lR /
Impossible d'arreter l'execution de ls avec ctrl-C

Assign + pipe = mauvais AST

La commande "TEST=blabla | ls" fait generer cet AST :

    "TEST=BLABLA"
         /  \
       "|" "ls"

au lieu de :

            "|"
            / \
           /   \
          /     \
         /       \
        /         \
"TEST=BLABLA"    "ls"

Mauvais AST

CMD = ls | ls -R / 2>&- | wc -l

la redirection se place entre les 2 pipes dans l'ast

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.