Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

169 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Minishell

As beautiful as a shell

μ‰˜λ§ŒνΌμ΄λ‚˜ μ•„λ¦„λ‹€μš΄ 그것

Summary: 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.

μš”μ•½: 이번 ν”„λ‘œμ νŠΈμ˜ λͺ©ν‘œλŠ” κ°„λ‹¨ν•œ μ‰˜μ„ λ§Œλ“œλŠ” κ²ƒμž…λ‹ˆλ‹€. λ§žμ•„μš”, λ‹Ήμ‹ λ§Œμ˜ μž‘μ€ bashλ‚˜ zshμ΄μš”. ν”„λ‘œμ„ΈμŠ€λ‚˜ 파일 λ””μŠ€ν¬λ¦½ν„°μ— λŒ€ν•΄ μ•„μ£Ό 많이 배우게 될 κ²λ‹ˆλ‹€.


Contents

Chapter Contents page
I Introduction 2
II Common Instructions 3
III Mandatory part 4
IV Bonus part 6

Chapter 1

Introduction


The existence of shells is linked to the very existence of IT. At the time, all coders agreed that communicating with a computer using aligned 1/0 switches was seriously irritating. It was only logical that they came up with the idea to communicate with a computer using interactive lines of commands in a language somewhat close to english.

μ‰˜μ€ IT의 νƒœμ΄ˆλΆ€ν„° ν•¨κ»˜ν–ˆμŠ΅λ‹ˆλ‹€. κ·Έ λ‹Ήμ‹œ, λͺ¨λ“  κ°œλ°œμžλ“€μ€ 1κ³Ό 0으둜만 이루어진 μŠ€μœ„μΉ˜λ‘œ 컴퓨터와 ν†΅μ‹ ν•˜λŠ” 것은 ꡉμž₯히 μ„±κ°€μ‹œλ‹€λŠ” 점에 λ™μ˜ν–ˆμ–΄μš”. 그리고 μ˜μ–΄μ™€ λΉ„μŠ·ν•œ μ–Έμ–΄λ‘œ μž‘μ„±λœ λͺ…λ Ήμ–΄μ˜ 쀄을 μ΄μš©ν•΄ 컴퓨터와 μ†Œν†΅ν•œλ‹€λŠ” 아이디어λ₯Ό λ– μ˜¬λ¦° 것도 λ‹Ήμ—°ν•œ μˆ˜μˆœμ΄μ—ˆμ£ .

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

Minishellκ³Ό ν•¨κ»˜λΌλ©΄, Windowsκ°€ μ‘΄μž¬ν•˜μ§€ μ•Šμ•˜μ„ μ‹œμ ˆ μ‚¬λžŒλ“€μ΄ κ²ͺμ—ˆλ˜ 문제λ₯Ό λ§ˆμ£Όν•΄λ³Ό 수 μžˆμ„ κ²λ‹ˆλ‹€.


Chapter 2

Common Instructions


  • Your project must be written in accordance with the Norm. If you have bonus files/functions, they are included in the norm check and you will receive a 0 if there is a norm error inside.

    ν”„λ‘œμ νŠΈλŠ” Norm κ·œμΉ™μ— 맞좰 μž‘μ„±λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. λ³΄λ„ˆμŠ€ 파일/ν•¨μˆ˜κ°€ μ‘΄μž¬ν•  경우, κ·Έ λ˜ν•œ norm 검사에 ν¬ν•¨λ˜λ©° norm errorκ°€ μžˆμ„ μ‹œ 0점을 λ°›κ²Œ λ©λ‹ˆλ‹€.

  • Your functions should not quit unexpectedly (segmentation fault, bus error, double free, etc) apart from undefined behaviors. If this happens, your project will be considered non functional and will receive a 0 during the evaluation.

    μ •μ˜λ˜μ§€ μ•Šμ€ λ™μž‘μ„ μ œμ™Έν•˜κ³ , μ—¬λŸ¬λΆ„μ΄ μž‘μ„±ν•˜μ‹  ν”„λ‘œκ·Έλž¨μ΄ 예기치 μ•Šκ²Œ μ€‘λ‹¨λ˜μ–΄μ„œλŠ” μ•ˆ λ©λ‹ˆλ‹€. (예λ₯Ό λ“€μ–΄, segmentation fault, bus error, double free λ“±) λ§Œμ•½ μ—¬λŸ¬λΆ„μ˜ ν”„λ‘œκ·Έλž¨μ΄ 예기치 μ•Šκ²Œ μ’…λ£Œλœλ‹€λ©΄, μ œλŒ€λ‘œ μž‘λ™ν•˜μ§€ μ•Šμ€ κ²ƒμœΌλ‘œ κ°„μ£Όλ˜μ–΄ ν‰κ°€μ—μ„œ 0점을 λ°›κ²Œ λ©λ‹ˆλ‹€.

  • All heap allocated memory space must be properly freed when necessary. No leaks will be tolerated.

    ν•„μš”ν•œ 경우 heap에 ν• λ‹Ήλœ λͺ¨λ“  λ©”λͺ¨λ¦¬ 곡간은 μ μ ˆν•˜κ²Œ ν•΄μ œλ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. λ©”λͺ¨λ¦¬ λˆ„μˆ˜λŠ” μš©λ‚©λ  수 μ—†μŠ΅λ‹ˆλ‹€.

  • If the subject requires it, you must submit a Makefile which will compile your source files to the required output with the flags -Wall, -Wextra and -Werror, and your Makefile must not relink.

    κ³Όμ œμ—μ„œ ν•„μš”ν•œ 경우, -Wall -Wextra -Werror ν”Œλž˜κ·Έλ₯Ό μ§€μ •ν•˜μ—¬ μ»΄νŒŒμΌμ„ μˆ˜ν–‰ν•˜λŠ” Makefile을 μ œμΆœν•΄μ•Ό ν•©λ‹ˆλ‹€. Makefile은 relink λ˜μ–΄μ„œλŠ” μ•ˆ λ©λ‹ˆλ‹€.

  • Your Makefile must at least contain the rules $(NAME), all, clean, fclean and re.

    Makefile은 μ΅œμ†Œν•œ $(NAME), all, clean, fclean, re κ·œμΉ™μ„ 포함해야 ν•©λ‹ˆλ‹€.

  • To turn in bonuses to your project, you must include a rule bonus to your Makefile, which will add all the various headers, librairies or functions that are forbidden on the main part of the project. Bonuses must be in a different file _bonus.{c/h}. Mandatory and bonus part evaluation is done separately.

    ν”„λ‘œμ νŠΈμ— λ³΄λ„ˆμŠ€λ₯Ό μ œμΆœν•˜λ €λ©΄, Makefile에 λ³΄λ„ˆμŠ€ κ·œμΉ™μ„ 포함해야 ν•©λ‹ˆλ‹€. 이 λ³΄λ„ˆμŠ€ κ·œμΉ™μ€ ν”„λ‘œμ νŠΈμ˜ 메인 νŒŒνŠΈμ—μ„œ κΈˆμ§€λ˜μ—ˆλ˜ λͺ¨λ“  λ‹€μ–‘ν•œ 헀더, 라이브러리, λ˜λŠ” ν•¨μˆ˜λ“€μ„ μΆ”κ°€ν•˜μ—¬μ•Ό ν•©λ‹ˆλ‹€. λ³΄λ„ˆμŠ€ κ³Όμ œλŠ” λ°˜λ“œμ‹œ _bonus.{c/h}λΌλŠ” λ³„λ„μ˜ νŒŒμΌμ— μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. λ°˜λ“œμ‹œ μˆ˜ν–‰ν•˜μ—¬μ•Ό ν•˜λŠ” 메인 파트의 평가와 λ³΄λ„ˆμŠ€ 파트의 ν‰κ°€λŠ” λ³„λ„λ‘œ μ΄λ€„μ§‘λ‹ˆλ‹€.

  • If your project allows you to use your libft, you must copy its sources and its associated Makefile in a libft folder with its associated Makefile. Your project’s Makefile must compile the library by using its Makefile, then compile the project.

    만일 ν”„λ‘œμ νŠΈμ—μ„œ μ—¬λŸ¬λΆ„μ˜ libft μ‚¬μš©μ„ ν—ˆμš©ν•œλ‹€λ©΄, μ†ŒμŠ€λ“€κ³Ό κ΄€λ ¨ Makefile을 ν•¨κ»˜ 루트 폴더 μ•ˆμ— μžˆλŠ” libft 폴더에 볡사해야 ν•©λ‹ˆλ‹€. ν”„λ‘œμ νŠΈμ˜ Makefile은 μš°μ„  libft의 Makefile을 μ‚¬μš©ν•˜μ—¬ 라이브러리λ₯Ό μ»΄νŒŒμΌν•œ λ‹€μŒ, ν”„λ‘œμ νŠΈλ₯Ό μ»΄νŒŒμΌν•΄μ•Ό ν•©λ‹ˆλ‹€.

  • We encourage you to create test programs for your project even though this work won’t have to be submitted and won’t be graded. It will give you a chance to easily test your work and your peers’ work. You will find those tests especially useful during your defence. Indeed, during defence, you are free to use your tests and/or the tests of the peer you are evaluating.

    이 κ³Όμ œλ¬Όμ„ μ œμΆœν•  ν•„μš”κ°€ μ—†κ³ , 채점 받을 ν•„μš”κ°€ 없을지라도, μ €ν¬λŠ” μ—¬λŸ¬λΆ„λ“€μ΄ ν”„λ‘œμ νŠΈλ₯Ό μœ„ν•œ ν…ŒμŠ€νŠΈ ν”„λ‘œκ·Έλž¨μ„ λ§Œλ“€ 것을 ꢌμž₯ν•©λ‹ˆλ‹€. 이것은 μ—¬λŸ¬λΆ„μ˜ 과제물과 λ™λ£Œλ“€μ˜ κ³Όμ œλ¬Όμ„ μ‰½κ²Œ ν…ŒμŠ€νŠΈν•  수 있게 λ„μšΈ κ²ƒμž…λ‹ˆλ‹€. λ˜ν•œ, 평가λ₯Ό μ§„ν–‰ν•  λ•Œ μ΄λŸ¬ν•œ ν…ŒμŠ€νŠΈ ν”„λ‘œκ·Έλž¨λ“€μ΄ 특히 μœ μš©ν•˜λ‹€λŠ” 사싀을 μ•Œκ²Œ 될 κ²ƒμž…λ‹ˆλ‹€. 평가 μ‹œμ—λŠ” μ—¬λŸ¬λΆ„μ˜ ν…ŒμŠ€νŠΈ ν”„λ‘œκ·Έλž¨κ³Ό 평가 λ°›λŠ” λ™λ£Œμ˜ ν…ŒμŠ€νŠΈ ν”„λ‘œκ·Έλž¨λ“€μ„ λ‹Ήμ—°νžˆ 자유둭게 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

  • Submit your work to your assigned git repository. Only the work in the git repository will be graded. If Deepthought is assigned to grade your work, it will be done after your peer-evaluations. If an error happens in any section of your work during Deepthought’s grading, the evaluation will stop.

    ν• λ‹Ήλœ git μ €μž₯μ†Œμ— κ³Όμ œλ¬Όμ„ μ œμΆœν•˜μ„Έμš”. 였직 git μ €μž₯μ†Œμ— μžˆλŠ” 과제물만 등급이 맀겨질 κ²ƒμž…λ‹ˆλ‹€. Deepthoughtκ°€ ν‰κ°€ν•˜λŠ” 과제의 κ²½μš°μ—”, λ™λ£Œν‰κ°€ 이후에 Deepthoughtκ°€ μˆ˜ν–‰λ©λ‹ˆλ‹€. λ§Œμ•½ Deepthought 평가 쀑에 였λ₯˜κ°€ λ°œμƒν•œλ‹€λ©΄, κ·Έ μ¦‰μ‹œ ν‰κ°€λŠ” 쀑지될 κ²ƒμž…λ‹ˆλ‹€.


Chapter 3

Mandatory part


ν”„λ‘œκ·Έλž¨ 이름 minishell
μ œμΆœν•  파일
Makefile λ§Œλ“€μ–΄μ•Ό 함
인자
μ‚¬μš©κ°€λŠ₯ν•œ μ™ΈλΆ€ ν•¨μˆ˜ readline, rl_on_new_line, rl_replace_line, rl_redisplay, add_history, printf, malloc, free, write, open, read, close, fork, wait, waitpid, wait3, wait4, signal, kill, exit, getcwd, chdir, stat, lstat, fstat, unlink, execve, dup, dup2, pipe, opendir, readdir, closedir, strerror, errno, isatty, ttyname, ttyslot, ioctl, getenv, tcsetattr, tcgetattr, tgetent, tgetflag, tgetnum, tgetstr, tgoto, tputs
직접 λ§Œλ“  libft μ‚¬μš© κ°€λŠ₯
μ„€λͺ… μ‰˜μ„ λ§Œλ“œμ„Έμš”

Your shell should:

λ‹Ήμ‹ μ˜ μ‰˜μ€:

  • Not interpret unclosed quotes or unspecified special characters like \ or ;.

    λ‹«νžˆμ§€ μ•Šμ€ λ”°μ˜΄ν‘œλ‚˜ νŠΉμ •λ˜μ§€ μ•Šμ€ 특수문자 (\λ‚˜ ; λ“±...) 을 ν•΄μ„ν•˜μ§€ μ•Šμ•„μ•Ό ν•©λ‹ˆλ‹€.

  • Not use more than one global variable, think about it and be ready to explain why you do it.

    μ „μ—­λ³€μˆ˜λŠ” ν•œ 개 이상을 μ‚¬μš©ν•  수 μ—†μœΌλ©°, μ™œ μ „μ—­λ³€μˆ˜λ₯Ό μ‚¬μš©ν–ˆλŠ”μ§€ 깊게 생각해 보고 κ·Έ 이유λ₯Ό μ„€λͺ…ν•  수 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€.

  • Show a prompt when waiting for a new command.

    μƒˆλ‘œμš΄ λͺ…λ Ήμ–΄λ₯Ό μž…λ ₯ν•  수 μžˆλŠ” ν”„λ‘¬ν”„νŠΈλ₯Ό λ³΄μ—¬μ€˜μ•Ό ν•©λ‹ˆλ‹€.

  • Have a working History.

    μž‘μ—… νžˆμŠ€ν† λ¦¬λ₯Ό κ°–κ³  μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€.

  • Search and launch the right executable (based on the PATH variable or by using relative or absolute path)

    (PATH λ³€μˆ˜λ‚˜ μƒλŒ€, μ ˆλŒ€ 경둜λ₯Ό ν™œμš©ν•˜μ—¬) μ˜¬λ°”λ₯Έ μ‹€ν–‰ νŒŒμΌμ„ μ°Ύμ•„ μ‹€ν–‰ν•  수 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€.

  • It must implement the builtins:

    λ‹€μŒμ˜ λ‚΄μž₯ κΈ°λŠ₯을 μ‹€ν–‰ν•  수 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€:

    • echo with option -n

      -n μ˜΅μ…˜μ„ μ‚¬μš©ν•  수 μžˆλŠ” echo

    • cd with only a relative or absolute path

      였직 μƒλŒ€ λ˜λŠ” μ ˆλŒ€κ²½λ‘œλ§Œ μ‚¬μš©ν•˜λŠ” cd

    • pwd with no options

      μ˜΅μ…˜μ΄ μ—†λŠ” pwd

    • export with no options

      μ˜΅μ…˜μ΄ μ—†λŠ” export

    • unset with no options

      μ˜΅μ…˜μ΄ μ—†λŠ” unset

    • env with no options or arguments

      μ˜΅μ…˜μ΄λ‚˜ μΈμžκ°’μ΄ μ—†λŠ” env

    • exit with no options

      μ˜΅μ…˜μ΄ μ—†λŠ” exit

  • ’ inhibit all interpretation of a sequence of characters.

    'λŠ” 일련의 λ¬Έμžμ—΄μ— λŒ€ν•œ 해석을 κΈˆμ§€ν•©λ‹ˆλ‹€.

  • " inhibit all interpretation of a sequence of characters except for $.

    "λŠ” $λ₯Ό μ œμ™Έν•œ λͺ¨λ“  λ¬Έμžμ—΄μ— λŒ€ν•œ 해석을 κΈˆμ§€ν•©λ‹ˆλ‹€.

  • Redirections:

    λ¦¬λ‹€μ΄λ ‰μ…˜:

    • < should redirect input.

      <λŠ” μž…λ ₯을 λ¦¬λ‹€μ΄λ ‰μ…˜ ν•˜μ—¬μ•Ό ν•©λ‹ˆλ‹€

    • > should redirect output.

      >λŠ” 좜λ ₯을 λ¦¬λ‹€μ΄λ ‰μ…˜ ν•˜μ—¬μ•Ό ν•©λ‹ˆλ‹€

    • << read input from the current source until a line containing only the delimiter is seen. it doesn’t need to update history!

      <<λŠ” ν˜„μž¬ μ†ŒμŠ€μ—μ„œ κ΅¬λΆ„μžλ₯Ό ν¬ν•¨ν•œ 쀄을 λ§Œλ‚˜κΈ° μ „κΉŒμ§€ μž…λ ₯값을 μ½μ–΄λ“€μž…λ‹ˆλ‹€. 기둝을 μ—…λ°μ΄νŠΈν•  ν•„μš”λŠ” μ—†μŠ΅λ‹ˆλ‹€!

    • >> should redirect output with append mode.

      >>λŠ” 좜λ ₯을 μΆ”κ°€ λͺ¨λ“œλ‘œ λ¦¬λ‹€μ΄λ ‰μ…˜ν•©λ‹ˆλ‹€.

  • Pipes | The output of each command in the pipeline is connected via a pipe to the input of the next command.

    νŒŒμ΄ν”„ | : 각 νŒŒμ΄ν”„λΌμΈλ§ˆλ‹€ λͺ…λ Ήμ–΄μ˜ 좜λ ₯값은 νŒŒμ΄ν”„λ‘œ μ—°κ²°λ˜μ–΄ λ‹€μŒ λͺ…λ Ήμ–΄μ˜ μž…λ ₯κ°’μœΌλ‘œ λ“€μ–΄κ°€μ•Ό ν•©λ‹ˆλ‹€.

  • Environment variables ($ followed by characters) should expand to their values.

    ν™˜κ²½ λ³€μˆ˜ ($ λ‹€μŒμ— λ¬Έμžμ—΄μ΄ μ˜€λŠ” ν˜•μ‹) 은 κ·Έλ“€μ˜ κ°’μœΌλ‘œ ν™•μž₯λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.

  • $? should expands to the exit status of the most recently executed foreground pipeline.
  • $?λŠ” κ°€μž₯ μ΅œκ·Όμ— μ‹€ν–‰ν•œ ν¬κ·ΈλΌμš΄λ“œ νŒŒμ΄ν”„λΌμΈμ˜ μ’…λ£Œ μƒνƒœλ₯Ό ν™•μž₯ν•˜μ—¬μ•Ό ν•©λ‹ˆλ‹€

  • ctrl-C, ctrl-D and ctrl-\ should have the same result as in bash.

    ctrl-C, ctrl-D, ctrl-\ λŠ” bash와 λ™μΌν•˜κ²Œ λ™μž‘ν•˜μ—¬μ•Ό ν•©λ‹ˆλ‹€.

  • When interactive:

    μƒν˜Έμž‘μš©μ΄ κ°€λŠ₯ν•  λ•Œ:

    • ctrl-C print a new prompt on a newline.

      ctrl-CλŠ” μƒˆλ‘œμš΄ 쀄에 μƒˆλ‘œμš΄ ν”„λ‘¬ν”„νŠΈλ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€

    • ctrl-D exit the shell.

      ctrl-DλŠ” μ‰˜μ„ μ’…λ£Œν•©λ‹ˆλ‹€.

    • ctrl-\ do nothing.

      ctrl-\은 μ•„λ¬΄λŸ° λ™μž‘λ„ ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

Anything not asked is not required.

μš”κ΅¬ν•˜μ§€ μ•Šμ€ 것듀을 λ§Œλ“œμ‹€ ν•„μš”λŠ” μ—†μŠ΅λ‹ˆλ‹€.

For every point, if you have any doubt take bash as a reference

과제의 μ–΄λ– ν•œ μ§€μ μ—μ„œλ“ , 의문점이 생긴닀면 bashλ₯Ό μ°Έκ³ ν•˜μ„Έμš”.


Chapter 4

Bonus part


  • If the Mandatory part is not perfect don’t even think about bonuses

    ν•„μˆ˜ νŒŒνŠΈκ°€ μ™„λ²½ν•˜μ§€ μ•ŠμœΌλ©΄ λ³΄λ„ˆμŠ€λŠ” μƒκ°ν•˜μ§€λ„ λ§ˆμ„Έμš”.

  • &&, || with parenthesis for priorities.

    κ΄„ν˜Έλ₯Ό μ΄μš©ν•΄ μš°μ„ μˆœμœ„λ₯Ό ν‘œν˜„ν•œ &&, ||

  • the wilcard * should work for the current working directory.

    μ™€μΌλ“œμΉ΄λ“œ *κ°€ ν˜„μž¬ μž‘μ—… 디렉토리에 λŒ€ν•΄ λ™μž‘ν•˜μ—¬μ•Ό ν•©λ‹ˆλ‹€.

About

A code repository designed to show the best GitHub has to offer.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages