Code Monkey home page Code Monkey logo

minishell's Introduction

MINISHELL

made by sojoo && heeskim

Welcome to KINDERshell๐Ÿฅš [์‚ฌ์ง„ ์‚ฝ์ž… ์˜ˆ์ •] ๊ฐœ๋ฐœ ๊ธฐ๊ฐ„ : 8/24 ~

1. Introduction

The objective of this project is for you to create a simple shell. Yes, your own little bash or zsh. You will learn a lot about processes and file descriptors.

With Minishell, youโ€™ll be able to travel through time and come back to problems people faced when Windows didnโ€™t exist.

2. Instructions : Write a shell

  • ์ธํ„ฐํ”„๋ฆฌํ„ฐ๋Š” ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ($> )๋ฅผ ๋„์›Œ์•ผํ•œ๋‹ค.

    • ์‚ฌ์šฉ์ž๊ฐ€ enter ํ‚ค๋ฅผ ๋ˆŒ๋Ÿฌ ๋ช…๋ น์ค„(command line)์„ ์ž…๋ ฅํ•  ๋•Œ ๊นŒ์ง€ ๊ธฐ๋‹ค๋ ค์•ผ ํ•œ๋‹ค.
    • ํ”„๋กฌํ”„ํŠธ๋Š” ๋ช…๋ น์ด ์™„์ „ํžˆ ์‹คํ–‰๋œ ํ›„์—๋งŒ ๋‹ค์‹œ ํ‘œ์‹œ๋œ๋‹ค.
  • ํ™˜๊ฒฝ๋ณ€์ˆ˜ PATH์™€ ์ƒ๋Œ€๊ฒฝ๋กœ, ์ ˆ๋Œ€ ๊ฒฝ๋กœ์— ๋”ฐ๋ผ ์‹คํ–‰ ํŒŒ์ผ(The executable)์„ ์ฐพ๊ณ  ์‹คํ–‰ํ•œ๋‹ค.

    • ์‹คํ–‰ ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•˜๊ณ  ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋‹ค์‹œ ํ‘œ์‹œํ•œ๋‹ค.
  • Working History๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

  • ์ „์—ญ๋ณ€์ˆ˜๋Š” 1๊ฐœ๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค.

  • ๋‹ซํžˆ์ง€ ์•Š์€ ๋”ฐ์˜ดํ‘œ๋‚˜, , ;, . ๊ฐ™์€ ํŠน์ˆ˜๋ฌธ์ž์— ๋Œ€ํ•ด์„œ ํ•ด์„ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค.

  • ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์‰˜ ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. (Builtin directory)

    • echo (-n option only)
    • cd (์ƒ๋Œ€๊ฒฝ๋กœ, ์ ˆ๋Œ€๊ฒฝ๋กœ๋งŒ)
    • pwd (option์ œ์™ธ)
    • export(option ์ œ์™ธ)
    • unset(option ์ œ์™ธ)
    • env (option, argument์ œ์™ธ)
    • exit (option ์ œ์™ธ))
  • ๋‹ค์Œ์˜ ๊ธฐ๋Šฅ๋“ค์„ Bash shell์™€ ์œ ์‚ฌํ•˜๊ฒŒ ๋™์ž‘ํ•ด์•ผํ•˜๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค.

    • ' , "
    • file redirection (<<, <, >, >>)
    • ํŒŒ์ดํ”„(|)
    • ํ™˜๊ฒฝ๋ณ€์ˆ˜($์ดํ›„์˜ ๋ณ€์ˆ˜ ex)$HOME )
    • $?(exit code)
    • ctrl-C, ctrl-D, ctrl-\
  • ์ด์™ธ์˜ ์ œ์‹œ๋˜์ง€ ์•Š์€ ์‚ฌํ•ญ๋“ค์€ ๋ฌด์‹œ๋˜์–ด๋„ ์ข‹๋‹ค.

  • ๋ชจ๋“  ์‚ฌํ•ญ์—์„œ Bash๋ฅผ ์ฐธ๊ณ ํ•˜๊ธธ ์ถ”์ฒœํ•œ๋‹ค.

3. Allowed Functions

  • malloc, free
  • read, write, open, close
  • opendir, readdir, closedir
  • getcwd, chdir
  • stat, lstat, fstat
  • fork, execve, wait, waitpid, wait3, wait4
  • signal, kill, exit
  • strerror, errno
  • dup, dup2, pipe

minishell's People

Contributors

lampolar avatar zoovely avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

zoovely

minishell's Issues

parse ํ•ด๊ฒฐ๊ณผ์ œ

  • heredoc์ด ์•ž์— ์žˆ๋Š” ํŒŒ์ผ๋ช…์€ aftertokenize๋•Œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ value๋กœ ์•ˆ๋ฐ”๊ฟ”์ค€๋‹ค (๋”ฐ์˜ดํ‘œ ์•ˆ์ด๋“  ๋ฐ–์ด๋“ )
  • siganl fork ์ „์— ๋ฌด์‹œ์‹œํ‚ค๊ณ , exitcode ์—…๋ฐ์ดํŠธ ์‹œ์ผฐ์„ ๋•Œ ๋‹ค์‹œ ์„ค์ •ํ•˜๋Š” ๊ฑฐ (cat | ls ํ›„ ctrl+C ๋ˆŒ๋ €์„ ๋–„ $?๊ฐ€ 0) -> execute_pipe norm check
  • export_builtin์—์„œ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•  ๋–„ leak ๋‚˜๋Š” ๋ถ€๋ถ„ ์ฐพ์•„์„œ ์ˆ˜์ •ํ•˜๊ธฐ

heredoc์‹œ ์‹œ๊ทธ๋„ ์•ˆ๋จนํž˜

cat๋งŒ ์‹คํ–‰ ํ›„ ๋ฌธ์ž์—ด ์ž…๋ ฅํ•˜๋‹ค๊ฐ€ ctrl+C ๋ˆ„๋ฅด๋ฉด ๋ฉˆ์ถ”๋Š”๋ฐ
<< ์‚ฌ์šฉํ•ด์„œ ๋ฌธ์ž์—ด ์ž…๋ ฅํ•˜๋Š” ๋ชจ๋“  ๊ฒƒ์—์„œ๋Š” ctrl+C๋ฅผ ๋ˆŒ๋Ÿฌ๋„ ์•ˆ๋ฉˆ์ถค
์™œ์ง€??? ์‹œ๊ทธ๋„์„ ๋ง‰๋Š” ๊ณณ์€ pipe๊ฐ€ root์ผ๋•Œ๋งŒ์ธ๋ฐ ํŒŒ์ดํ”„ ์—†๋Š” line์—์„œ๋„ ์•ˆ๋จนํž˜

ํŒŒ์ผ ์ •๋ฆฌ ํ•„์š”

token*.c ์—์„œ unused variable๋“ค ์ •๋ฆฌํ•˜๊ณ ,
ํ๋ฆ„ ๋”ฐ๋ผ๊ฐ€๋ฉด์„œ ์•ˆ ์“ฐ๋Š” ์ฝ”๋“œ ์ œ๊ฑฐํ•˜๊ณ ,
์„ค๋ช…์šฉ ์ฃผ์„ ๋‹ฌ์•„๋†“๊ธฐ
-Wall -Wextra -Werror๋กœ ์ปดํŒŒ์ผํ•ด์„œ ์˜ค๋ฅ˜ ์ฐพ๊ธฐ

exitํ˜ธ์ถœ์‹œ free์ฒ˜๋ฆฌ์— ๊ด€ํ•˜์—ฌ

๋ชจ๋“  ํ”„๋กœ์„ธ์Šค์—์„œ exitํ˜ธ์ถœํ•  ๋•Œ๋งˆ๋‹ค free๋ฅผ ๋‹ค ํ•ด์ค„๊ฑด์ง€...?
์•„๋‹ˆ๋ฉด ์ž์‹ํ”„๋กœ์„ธ์Šค๋Š” ๊ทธ๋ƒฅ ๋ณด๋‚ด์ฃผ๊ณ  ๋ถ€๋ชจํ”„๋กœ์„ธ์Šค์—์„œ๋งŒ ํ”„๋ฆฌํ•ด์ค„๊ฑด์ง€

exit error message ์ถ”๊ฐ€

bash-3.2$ exit 9223372036854775808
exit
bash: exit: 9223372036854775808: numeric argument required

KINDER๐Ÿฅš > exit 9223372036854775808
๐Ÿฅš KINDER JOY SHELL EXIT ๐Ÿฅš
KINDER๐Ÿฅš >

  • exit ์—„์ฒญ ํฌ๊ฑฐ๋‚˜ ์ž‘์€ ์ˆซ์ž => numberic ์—๋Ÿฌ ์ถœ๋ ฅ

(๊ฐ€๋Šฅํ•œ ์ˆซ์ž ์ตœ๋Œ€๋Š” 2^63-1, ์ตœ์†Œ๋Š” -(2^64))

ํ…Œ์ŠคํŠธ ์ค‘ ๋ฌธ์ œ

echo $$๋Š” PID๋ฅผ ์ถœ๋ ฅ
์šฐ๋ฆฌ๋Š” ์•„๋ฌด๊ฒƒ๋„ ์•ˆ์ถœ๋ ฅ

echo $'$HOME'$'$HOME'$'$HOME'$
์šฐ๋ฆฌ = $$HOME$$HOME$$HOME$
bash = $HOME$HOME$HOME$

echo $"$HOME"$'$HOME'$"$HOME"$
์šฐ๋ฆฌ = ๋ฉˆ์ถค ! !
bash = /Users/sojoo$HOME/Users/sojoo$

export ๊ฐ’ ์ถ”๊ฐ€์‹œ ํŒŒ์‹ฑ์ถ”๊ฐ€

KINDER๐Ÿฅš > export LS='ls -l hello | cat < gogo.log'
KINDER๐Ÿฅš > $LS
KINDER: ls -l hello | cat < gogo.log: command not found
KINDER๐Ÿฅš > ls -l hello | cat < gogo.log
KINDER: No such file or directory
ls: hello: No such file or directory

bash-3.2$ export LS='ls -l hello | cat < gogo.log'
bash-3.2$ $LS
ls: <: No such file or directory
ls: cat: No such file or directory
ls: gogo.log: No such file or directory
ls: hello: No such file or directory
ls: |: No such file or directory

์ŠคํŽ˜์ด์Šค๋ฐ” ๊ธฐ์ค€์œผ๋กœ ํ•˜๋‚˜ํ•˜๋‚˜๋ฅผ ๋‹ค์‹œ ํŒŒ์‹ฑํ•ด์„œ ์‹คํ–‰์‹œ์ผœ์•ผํ•จ.
....ํ•ด..? ๋ง์•„...?

redirection ๋””๋ฒจ๋กญ

2> : standard error๋ฅผ ๋ฆฌ๋‹ค์ด๋ ‰์…˜
&>word ํ‘œ์ค€ ์ถœ๋ ฅ๊ณผ ํ‘œ์ค€์—๋Ÿฌ๋ฅผ ๋™์‹œ์— ๋ฆฌ๋‹ค์ด๋ ‰์…˜

& word
word 2>&1

checklist

$? + $?


KINDER๐Ÿฅš > $? + $?
KINDER: Execute failed

bash-3.2$ $? + $?
bash: 0: command not found

์ตœํ›„์ •๋ฆฌ

ํด๋” ๋ฐ”๊นฅ์— ์žˆ๋Š” ํŒŒ์ผ๋“ค ๋†ˆ์ฒดํฌ ํ•˜๊ธฐ
leaks ์ฒดํฌ ํ•˜๊ธฐ
๊ฐ์ข… ํ…Œ์ŠคํŠธ ์ง„ํ–‰
checklist ํ™•์ธ
์„ค๋ช… ์—ฐ์Šต?

$?์ฒ˜๋ฆฌ

์ฒ˜๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ํ•  ๊ฒƒ์ธ๊ฐ€..

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.