GithubHelp home page GithubHelp logo

uael / 42sh Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 2.0 1.65 MB

42 shell school project, support for job-control, shell script, globbing, aliases, ..

Home Page: https://www.42.fr

License: The Unlicense

CMake 0.63% Makefile 1.40% C 75.40% Shell 22.13% Elixir 0.44%
c job-control shell shell-script

42sh's Introduction

42sh

Build Status

Grade:

125/100 (outstanding project * 5)

Subject:

Subject

Mandatory part:

  • Prompt without line edition.
  • Builtins cd, echo, exit, env, setenv, unsetenv with there options.
  • Executing simple commands with there parameters using PATH.
  • Support for redirection >, >>, <and |.
  • Logical operand &&and ||.
  • Separator ;.

Optional feature (five of theses are mandatory to validate the project):

  • Inhibitors ", 'and \.
  • Advanced redirections: aggregation of file output and heredoc <<.
  • Globbing: *, ?, [], {}, etc.
  • Backquotes `.
  • Subshell with operand ().
  • Local variable and builtin unset and export.
  • History with builtin historyand ! with options.
  • Advanced line edition.
  • File descriptors and builtin read with options.
  • Dynamical autocompletion.

Optional feature highly appreciated:

  • Job Control and builtins job, fg, bg and operand &.
  • Shell Scripting: bang (!), variable assignements, brace group, if, while, until, for and functions

Bonuses

  • Advanced dollar expansion $(..), $((..)), $[..]
  • Tilde expansion ~, ~<username>, ~-, ~+
  • Range expansion {<START>..<END>} and {<START>..<END>..<INCREMENT>}
  • Advanced redirections operator &>, &>>, <>, <<< and |&
  • Aliases, builtin alias alias [-p] [name[=value] …] and expansion
  • Builtin env advanced options -u name and [name=value]
  • Inline variables [name=value] binary [arguments...]
  • Binary hashtable
  • Rights in the PATH

Usage

Usage: ./42sh [option] [script-file] [script arguments...]
ush options:
	--help: this *useful* help message!
ush keymap:
	<ctrl+A|home>: Go to begin of line.
	<ctrl+E|end>: Go to end of line.
	<ctrl+V>: Enter visual mode.
	<ctrl+Y>: Yank in visual mode.
	<ctrl+P>: Paste.
	<ctrl+D>: Exit or delete in visual mode.
	<ctrl+C>: Cancel line edition.
	<ctrl+L>: Clear the screen.
	<shift+[left|right]>: Move per word.
	<shift+[up|down]>: Move per line.
	<up>: Go up in the history.
	<down>: Go down in the history.
	!!: Retype the last command.
	!n: Retype the n command from the begin of history.
	!-n: Retype the -n command from the last command.
	!name: Search for a command beginning with name.

42sh's People

Contributors

clemalfroy avatar jeanmax avatar uael avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

42sh's Issues

bug 9

(ush)$>cd
(ush)$>[CTRL-D]

	trace de SAN:

Direct leak of 4608 byte(s) in 1 object(s) allocated from:
#0 0x7faf041bed28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
#1 0x55b230a88f31 in ft_malloc src/mem/alloc.c:22
#2 0x55b230a88fb6 in ft_realloc src/mem/alloc.c:40
#3 0x55b230a89d8e in ft_vecalloc src/ds/alloc.c:50
#4 0x55b230a842e8 in ft_vecgrow src/ds/grow.c:36
#5 0x55b230a8480c in ft_vecnpush src/ds/npush.c:40
#6 0x55b230a8545b in ft_vecpush src/ds/push.c:27
#7 0x55b230a70081 in sh_evalargv src/eval/argv.c:48
#8 0x55b230a7406c in sh_evalsimple src/eval/simple.c:42
#9 0x55b230a70ca5 in sh_evalcmd src/eval/cmd.c:23
#10 0x55b230a7244d in sh_evalpipeline src/eval/pipeline.c:21
#11 0x55b230a6f476 in sh_evalandor src/eval/andor.c:39
#12 0x55b230a7217e in sh_evallist src/eval/list.c:70
#13 0x55b230a6f084 in sh_eval src/eval.c:81
#14 0x55b230a7f3e1 in sh_run src/shell.c:111
#15 0x55b230a7aeb0 in main src/main.c:39
#16 0x7faf03d7e2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

Indirect leak of 256 byte(s) in 1 object(s) allocated from:
#0 0x7faf041bed28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
#1 0x55b230a88f31 in ft_malloc src/mem/alloc.c:22
#2 0x55b230a88fb6 in ft_realloc src/mem/alloc.c:40
#3 0x55b230a89d8e in ft_vecalloc src/ds/alloc.c:50
#4 0x55b230a842e8 in ft_vecgrow src/ds/grow.c:36
#5 0x55b230a8480c in ft_vecnpush src/ds/npush.c:40
#6 0x55b230a8545b in ft_vecpush src/ds/push.c:27
#7 0x55b230a702bb in sh_evalargv src/eval/argv.c:64
#8 0x55b230a7406c in sh_evalsimple src/eval/simple.c:42
#9 0x55b230a70ca5 in sh_evalcmd src/eval/cmd.c:23
#10 0x55b230a7244d in sh_evalpipeline src/eval/pipeline.c:21
#11 0x55b230a6f476 in sh_evalandor src/eval/andor.c:39
#12 0x55b230a7217e in sh_evallist src/eval/list.c:70
#13 0x55b230a6f084 in sh_eval src/eval.c:81
#14 0x55b230a7f3e1 in sh_run src/shell.c:111
#15 0x55b230a7aeb0 in main src/main.c:39
#16 0x7faf03d7e2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

Indirect leak of 3 byte(s) in 1 object(s) allocated from:
#0 0x7faf041bed28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
#1 0x55b230a88f31 in ft_malloc src/mem/alloc.c:22
#2 0x55b230a894eb in ft_strdup src/str/str_2.c:41
#3 0x55b230a702f4 in sh_evalargv src/eval/argv.c:64
#4 0x55b230a7406c in sh_evalsimple src/eval/simple.c:42
#5 0x55b230a70ca5 in sh_evalcmd src/eval/cmd.c:23
#6 0x55b230a7244d in sh_evalpipeline src/eval/pipeline.c:21
#7 0x55b230a6f476 in sh_evalandor src/eval/andor.c:39
#8 0x55b230a7217e in sh_evallist src/eval/list.c:70
#9 0x55b230a6f084 in sh_eval src/eval.c:81
#10 0x55b230a7f3e1 in sh_run src/shell.c:111
#11 0x55b230a7aeb0 in main src/main.c:39
#12 0x7faf03d7e2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

SUMMARY: AddressSanitizer: 4867 byte(s) leaked in 3 allocation(s).

######################################################

Bug5

base64 /dev/urandom | head -c 1000 | grep 42 | wc -l | sed -e 's/1/Yes/g' -e 's/0/No/g'

bug 13

si Malloc renvoie Null le projet segfault, on peut le verifier en remplacant malloc par notre propre malloc

bug 12

-doit afficher ls
true || false && ls

Builtins

  • echo
  • cd
  • setenv
  • unsetenv
  • env
  • exit
  • export
  • unset
  • set
  • fg
  • bg
  • jobs

bug 2

/t/21sh ❯ ls\

;
ush: ls;: Command not found
ls;
^
/t/21sh ❯

Bug1

ush: Expected <filename>' got in'
echo toto > in ; cat -e >out<in ; cat out ; rm out in

Fix var scope

$> FOO=bar echo $FOO

$> echo $FOO
bar
$> FOO=bar; echo $FOO
bar
$> FOO=baz
$> echo $FOO
baz
$> FOO= echo $FOO
baz
$> echo $FOO
baz
$> FOO=
$> echo $FOO
$> 

Parse error corrections

When multiple errors appends, all are reported, the first is always a consequences of followig.
Only report the first by returning 2 on error instead of 1 to handle unexpected token when 1

bug 11

-fait une erreur de write
$> echo >&-

bug 10

-bloque le shell:

  • $> echo >&- 2>&-
  • $> /a | cat /dev/random | base64 > tutu
  • $> cat | merde | ls
  • $> cat /dev/random|base64|head -c8 (ca va etre test en correction ca )

Subshell expansion to word token

perform a pipe where the child is the subshell ans the parent the shell that read from stdin and append to a dynamic buffer, then replace token value by this tring

bug5

shift + tab = segfault

Evaluation

  • pipes
  • and/or
  • semicolon
  • ampersand
  • bang
  • PATH lookup
    • hashtable
      • search and add if not found
      • remove or update if changes
    • corresponding exit code
  • Executable rights
  • redirections
    • <
    • >
    • >|
    • <<
    • <<-
    • >>
    • <>
    • >&
    • <&
  • subshell

bug4

ctrl + z when nothing runs and ctrl + \

bug 3

➜ 21sh git:(test) env -i ./21sh
/U/c/21sh ❯ echo $PATH

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.