minishell - KimTaebin-ai/study_posts GitHub Wiki

ํ•„์š” ๊ฐœ๋… ๋ฐ ํ•™์Šต ๋‚ด์šฉ

https://github.com/42-gyeongsan-minishell

history ๊ดœ์ฐฎ์€ ๋ธ”๋กœ๊ทธ ๊ทผ๋ฐ history ๋ช…๋ น์–ด๋ฅผ ๊ตฌํ˜„ํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ readline ํ•จ์ˆ˜๋กœ ๋ช…๋ น์–ด๋ฅผ ๋„ฃ์„ ๋•Œ add_history ํ•จ์ˆ˜๋กœ ๊ฐ’์„ ์ €์žฅ ์ด ๋‚ด์šฉ์€ ํ™”์‚ดํ‘œ ์œ„ ๋ฐฉํ–ฅ์„ ๋ˆ„๋ฅด๋ฉด ๋ฐ”๋กœ๋ฐ”๋กœ ๋‚˜์˜ด

$? ๊ฐ€์žฅ ์ตœ๊ทผ์— ์‹คํ–‰ํ•œ ๋ช…๋ น์–ด์˜ ๊ฒฐ๊ณผ๊ฐ’์„ ์ถœ๋ ฅํ•จ 0์ผ ๊ฒฝ์šฐ true, 127์ผ ๊ฒฝ์šฐ false์ด๋‹ค. ์•„์‹œ๊ฒ ๋ƒ

image

๊ณผ์ œ ์š”๊ตฌ ์‚ฌํ•ญ

  1. History ๊ธฐ๋Šฅ ๊ตฌํ˜„
  2. ์œ„์น˜๋ฅผ ์ฐพ์•„ (PATH๋ณ€์ˆ˜, ์ƒ๋Œ€, ์ ˆ๋Œ€ ๊ฒฝ๋กœ) ํŒŒ์ผ ์‹คํ–‰ ๊ตฌํ˜„
  3. ๋‹ซํžˆ์ง€ ์•Š์€ ๋”ฐ์˜ดํ‘œ๋‚˜ ๋ช…์‹œ๋˜์ง€ ์•Š์€ ํŠน์ˆ˜๋ฌธ์ž (\๋‚˜ ; ๋“ฑ...) ์„ ํ•ด์„ํ•˜์ง€ ์•Š์•„์•ผ ํ•ฉ
  4. ๋”ฐ์˜ดํ‘œ (') valid ์ฒดํฌ
  5. '' ์•ˆ์— ์žˆ๋Š” metacharacter (์ •๊ทœ์‹) ํ•ด์„ ๋…ธ๋…ธ
  6. "" ์•ˆ์— ์žˆ๋Š” $ (๋‹ฌ๋Ÿฌ๋ฅผ ์ œ์™ธํ•œ) metacharacter (์ •๊ทœ์‹) ํ•ด์„ ๋…ธ๋…ธ
  7. ๋ฆฌ๋‹ค์ด๋ ‰์…˜ >, >> ๊ธฐ๋Šฅ ๊ตฌํ˜„
  8. ํŒŒ์ดํ”„ ( | ๋ฌธ์ž) ๊ตฌํ˜„
  9. $ ๋’ค์— ์˜ค๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํ™œ์šฉ ๊ฐ€๋Šฅ
  10. $? ๊ฐ€์žฅ ์ตœ๊ทผ์— ์‹คํ–‰ํ•œ ํฌ๊ทธ๋ผ์šด๋“œ ํŒŒ์ดํ”„๋ผ์ธ์˜ ์ข…๋ฃŒ ์ƒํƒœ๋กœ ํ™•์žฅ
  11. ctrl-C, ctrl-D, ctrl-\ ๊ธฐ๋Šฅ ๊ตฌํ˜„

ctrl-C๋Š” ์ƒˆ๋กœ์šด ์ค„์— ์ƒˆ๋กœ์šด ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ถœ๋ ฅ

ctrl-D๋Š” ์…ธ์„ ์ข…๋ฃŒ

ctrl-\์€ ์•„๋ฌด๋Ÿฐ ๋™์ž‘๋„ ํ•˜์ง€ ์•Š์Œ

  1. -n ์˜ต์…˜์„ ํฌํ•จํ•œ echo
  2. ์ƒ๋Œ€ ๋˜๋Š” ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋งŒ ์ฒ˜๋ฆฌํ•˜๋Š” cd
  3. ์˜ต์…˜์ด ์—†๋Š” pwd
  4. ์˜ต์…˜์ด ์—†๋Š” export
  5. ์˜ต์…˜์ด ์—†๋Š” unset
  6. ์˜ต์…˜์ด๋‚˜ ์ธ์ž๊ฐ€ ์—†๋Š” env
  7. ์˜ต์…˜์ด ์—†๋Š” exit

๊ฐœ๋ฐœ ์ˆœ์„œ

  1. readline Makefile์— -lreadline flag ์ถ”๊ฐ€ ํ•„์š”
  2. add_history() ํ•จ์ˆ˜ ์ฒ˜๋ฆฌ