Skip to content

gotjd7837/minishell

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

1. minishell

์ด ํ”„๋กœ์ ํŠธ๋Š” Bash๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ POSIX shell์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

์™ผ์ชฝ : minishell

์˜ค๋ฅธ์ชฝ : zsh

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2024-06-29 แ„‹แ…ฉแ„’แ…ฎ 5 43 23

2. ์‹คํ–‰ ๋ฐฉ๋ฒ•

minishell์„ ์ปดํŒŒ์ผ ํ•˜๊ธฐ ์œ„ํ•ด GNU์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ readline์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

mac OS

brew install readline@8.1

linux

sudo apt install libreadline-dev

arm64 ์•„ํ‚คํ…์ณ์—์„œ๋Š” rl_replace_line() ํ•จ์ˆ˜๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ์ฃผ์„์ฒ˜๋ฆฌ ํ•˜๋ฉด ํ”„๋กœ๊ทธ๋žจ์ด ์ •์ƒ์ ์œผ๋กœ ์ปดํŒŒ์ผ ๋ฉ๋‹ˆ๋‹ค.

๋ฃจํŠธ์— (all, clean, fclean, re)๊ทœ์น™์„ ์ œ๊ณตํ•˜๋Š” Makefile์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผ ํ•˜์—ฌ minishellํ”„๋กœ๊ทธ๋žจ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

make all

  • minishell ํ”„๋กฌํ”„ํŠธ ์‹คํ–‰

./minishell

3. Features

  1. ์‰˜์˜ ์ „์ฒด ํ๋ฆ„์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค: ์‚ฌ์šฉ์ž ์ž…๋ ฅ์—์„œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํ™•์žฅ -> ํ™•์žฅ๋œ ์ž…๋ ฅ ํ† ํฐํ™” -> ์‹คํ–‰.
  2. ๋ฉ€ํ‹ฐ ํŒŒ์ดํ•‘, ๋ฉ€ํ‹ฐ ๋ฆฌ๋””๋ ‰์…˜ ๊ฐ€๋Šฅ.
  3. Heredoc์€ ์ž…๋ ฅ์—์„œ ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
  4. $? ์‚ฌ์šฉ ๊ฐ€๋Šฅ.
  5. ์‚ฌ์šฉ์ž ์ž…๋ ฅ์˜ quotes ์ฒ˜๋ฆฌ, ๋ฆฌ๋””๋ ‰์…˜, ํŒŒ์ดํ”„๊ฐ€ ์ œ๋Œ€๋กœ ํ˜•์„ฑ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๊ตฌ๋ฌธ ์˜ค๋ฅ˜ ๋ฐœ์ƒ.
  6. \, ; ๋“ฑ์˜ ํŠน์ˆ˜ ๋ฌธ์ž๋Š” ์ง€์›๋˜์ง€ ์•Š์ง€๋งŒ \\ ๋Š” ํŒŒ์ผ ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ.
  7. Ctrl + C, Ctrl + D, Ctrl + \๋Š” Bash์™€ ๋™์ผํ•˜๊ฒŒ ๊ตฌํ˜„.
  8. Readline ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ vim๊ณผ ๊ฐ™์€ ํŽธ์ง‘ ์ง€์›.
  9. add_history ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ ํžˆ์Šคํ† ๋ฆฌ ๊ด€๋ฆฌ. ๋”ฐ๋ผ์„œ ํ‚ค๋ณด๋“œ์˜ ํ™”์‚ดํ‘œ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ.
  10. ์—ฌ๋Ÿฌ ๋‚ด์žฅ ๋ช…๋ น์–ด๊ฐ€ ๊ตฌํ˜„๋จ. (echo, cd, pwd, export, unset, env, exit)

4. ํ—ˆ์šฉ ํ•จ์ˆ˜

  1. open on <unistd.h>
  2. close on <unistd.h>
  3. read on <unistd.h>
  4. write on <unistd.h>
  5. unlink on <unistd.h>
  6. fork on <unistd.h>
  7. dup on <unistd.h>
  8. dup2 on <unistd.h>
  9. pipe on <unistd.h>
  10. execve on <unistd.h>
  11. getcwd on <unistd.h>
  12. chdir on <unistd,h>
  13. isatty on <unistd.h>
  14. ttyname on <unistd.h>
  15. ttyslot on <unistd.h>
  16. errno on <errno.h>
  17. printf on <stdio.h>
  18. strerror on <string.h>
  19. malloc on <stdlib.h>
  20. free on <stdlib.h>
  21. getenv on <stdlib.h>
  22. exit on <stdlib.h>
  23. kill on <signal.h>
  24. signal on <signal.h>
  25. opendir on <dirent.h>
  26. closedir on <dirent.h>
  27. readdir on <dirent.h>
  28. tcgetattr on <term.h>
  29. tcsetattr on <term.h>
  30. tgetent on <term.h>
  31. tgetflag on <term.h>
  32. tgetnum on <term.h>
  33. tgetstr on <term.h>
  34. tgoto on <term.h>
  35. tputs on <term.h>
  36. ioctl on <sys/ioctl.h>
  37. wait3 on <sys/wait.h>
  38. wait4 on <sys/wait.h>
  39. wait on <sys/wait.h>
  40. waitpid on <sys/wait.h>
  41. stat on <sys/stat.h>
  42. lstat on <sys/stat.h>
  43. fstat on <sys/stat.h>
  44. readline on <readline/readline.h>
  45. rl_on_new_line on <readline/readline.h>
  46. rl_replace_line on <readline/readline.h>
  47. rl_redisplay on <readline/readline.h>
  48. add_history on <readlien/history.h>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 96.7%
  • Makefile 3.3%