Skip to content

furyxGG/mini-hell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minihell Manual

Bu dosya, projedeki mini shell'in nasil kullanildigini ve kodun hangi asamalardan gectigini anlatir. Icerik kodun mevcut davranisina gore hazirlanmistir.

1) Derleme ve Calistirma

Derleme

make

Calistirma

./minihell

2) Kisa Ozet

minihell su akisi izler:

  1. Prompt olusturulur.
  2. readline ile satir okunur.
  3. Parser satiri token'lara ayirir.
  4. Expansion ($VAR, $?) uygulanir.
  5. Komutlar pipe bolumlerine ayrilir.
  6. Builtin ise parent'ta (tek komutsa), degilse pipeline/external akisinda calistirilir.
  7. Redirection ve pipe fd'leri uygulanir.
  8. Cikis kodu g_status_code icinde tutulur.

3) Prompt ve Giris

Prompt formati kabaca:

USER@program:aktif_dizin$ 
  • USER env'den cekilir.
  • Dizin HOME altindaysa ~ ile kisaltilir.
  • Ctrl+C yeni satira gecirir ve prompt'u yeniler.
  • Ctrl+D (EOF) shell'den cikar.

4) Parser: Token Tipleri

Parser su tipleri uretir:

  • p: pipe (|)
  • o: redirection operatorleri (<, >, <<, >>)
  • w: normal word
  • q: tek tirnak icindeki word ('...')
  • Q: cift tirnak icindeki word ("...")

Syntax kontrolleri

Asagidaki durumlar syntax error verir:

  • Satir pipe ile baslar veya biter
  • Ardisik pipe (|| gibi parser seviyesinde iki pipe token)
  • Redirection operatorunden sonra word gelmemesi
  • Kapanmamis tirnak

5) Expansion Kurallari

Expansion w ve Q token'larinda calisir, q (tek tirnak) icinde calismaz.

Desteklenenler:

  • $VAR
  • $? (son cikis kodu)

Ayrica parser sonrasinda bitisik token birlestirme vardir. Ornek:

"abc"$USER'def'

tek argumana donusturulur.

6) Execution Model

Tek komut + builtin

  • cd, echo, env, pwd, unset, export
  • Tek komutsa parent process icinde calisir.
  • Bu sayede cd, export, unset ortam degisiklikleri kalici olur.

Pipeline veya external komut

  • Pipeline tarafinda fork + pipe + dup2 akisi vardir.
  • Son komutun cikis status'u g_status_code olur.
  • External komutlar PATH uzerinden bulunur ve execve ile calisir.

7) Redirection ve Pipe

Desteklenen redirection:

  • < file
  • > file
  • >> file
  • << limiter (heredoc)

Notlar:

  • Ayni komutta birden fazla redirection varsa son gecerli olan etkili olur.
  • Acilis hatalari (No such file, Permission denied) stderr'e yazilir.
  • Pipeline'da gereksiz fd'ler kapatilir.

8) Builtin Komutlar ve Flagler

echo

Kullanim:

echo [flags] [arg ...]

Desteklenen flag:

  • -n (newline basmaz)
  • -nnn gibi tekrarlar da kabul edilir (hepsi -n sayilir)

Ornek:

echo hello
echo -n hello

cd

Kullanim:

cd [path]
cd -
cd ~
cd ~/alt_dizin

Davranis:

  • Arguman yoksa HOME
  • cd - ise OLDPWD
  • Basarili oldugunda PWD/OLDPWD guncellenir
  • cd fazla argumanda hata verir

pwd

Kullanim:

pwd

Aktif dizini yazar.

env

Kullanim:

env

Sadece KEY=VALUE formatindaki env satirlarini yazar.

export

Kullanim:

export
export KEY=VALUE
export KEY

Davranis:

  • Argumansiz: tum env'i declare -x ... formatinda yazar
  • KEY=VALUE: set/update
  • KEY: bos degerle ekleyebilir
  • Gecersiz isimde hata verir

unset

Kullanim:

unset KEY [KEY ...]

Verilen key'leri env listesinden siler.

exit

Kullanim:

exit
exit N
exit numeric_arg extra_arg

Davranis:

  • exit: mevcut g_status_code ile cikar
  • exit N: N unsigned char'a normalize edilerek cikar
  • Sayisal olmayan arguman: mesaj basar, kod 2 ile cikar
  • Cok arguman: mesaj basar, shell acik kalir, status 1

9) Cikis Kodlari

  • Basarili komutlar genelde 0
  • Ctrl+C -> 130
  • Ctrl+\ -> 131
  • Syntax error -> 2

10) Destek Durumu ve Sinirlar

Bu implementation su an su davranislara odakli:

  • Komut, pipe, redirection, heredoc, expansion
  • Temel builtin seti

Asagidaki kabuk ozellikleri tam bash kapsami degildir:

  • &&, ||, () gibi kontrol operatorleri
  • Gelismis wildcard/glob davranislari
  • Alt-shell ve ileri seviye bash ozellikleri

11) Hata Ayiklama Ipuclari

Valgrind (tek run)

printf 'echo hi\nexit\n' | valgrind \
  --leak-check=full \
  --show-leak-kinds=all \
  --suppressions=valgrind_readline.supp \
  ./minihell

Uzun testte noise azaltma

Pipe/fork testlerinde child process raporlari cok olabilir. Ana akisi temiz gormek icin:

valgrind --trace-children=no ...

Bu durumda parent shell'in bellek ozetini daha temiz gorursun.

About

Ecole 42 MiniShell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors