1 / 15

Kabuk Programlama Shell Scripting(bash)

Kabuk Programlama Shell Scripting(bash). Aslı Ergün. Shell Türleri. Bourne Bash Z-dhell C-shell TC-shell Korn Man csh yazarsak bilgi ediniriz. Hangi Kabuktayız?. Echo $SHELL yazarsak /bin/sh ise Bourne /bin/ksh93 ise Korn /bin/bash ise Bash /bin/zsh ise Z shell

maxine
Download Presentation

Kabuk Programlama Shell Scripting(bash)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Kabuk ProgramlamaShell Scripting(bash) Aslı Ergün

  2. Shell Türleri • Bourne • Bash • Z-dhell • C-shell • TC-shell • Korn • Man csh yazarsak bilgi ediniriz.

  3. Hangi Kabuktayız? • Echo $SHELL yazarsak • /bin/sh ise Bourne • /bin/ksh93 ise Korn • /bin/bash ise Bash • /bin/zsh ise Z shell • /bin/csh ise C shell • /bin/tcsh ise TC shell

  4. Bash scripting dilidir. "Hello World" script ile baslayalım. Uzantısı .sh olacak bir dosya içine script yazılır. Dosyaya, • #!/bin/bash • echo "Hello, World " yaz • Mod değiştir chmoda+x /where/i/saved/it/hello_world.sh veya • chmod 700 /where/i/saved/it/hello_world.sh • /where/i/saved/it/hello_world.sh yazarak calıstır. • Pwd calisilan klasoru gosterir.

  5. Değişkenler • #!/bin/bashSTRING="HELLO WORLD!!!"echo $STRING

  6. Yönlendirme • ls > dosya.txt • sort < dosya.txt > sirali.txt • date >> sirali.txt

  7. Değer Girme(read) • #!/bin/bash • clear • echo " Adınızı Girin" • read name • echo " Yasınızı girin" • read age • echo " Cinsiyet girin: K/E" • read sex • echo " Siz $age yasında $sex cinsiyetinde $name adlı kisisiniz« • Aynısı echo olmadan read komutu ile: • clear read -p "Please enter your name : " name read -p "Please enter your age : " age read -p "Please enter your sex. Male/Female : " sex echo "So you're a $age year old $sex called $name« • Temiz bosluklar basacak sekilde: • clear read -p "Please enter your name : " name echo "" read -p "Please enter your age : " age echo "" read -p "Please enter your sex. Male/Female : " sex echo "" echo "So you're a $age year old $sex called $name"Now we have an efficient and clean Bash script.

  8. If Cumleleri • if [ $fruit = " elma " ] then echo " Elmalar..." elif [ $fruit = armut] then echo " Armutlar..." elif [ $fruit = muz ] then echo " Muzlar" else echo " Geriye Portakal kaldı!" fi • #!/bin/bashdirectory="./BashScripting"# bash check if directory existsif [ -d $directory ]; thenecho "Directory exists"else echo "Directory does not exists"fi

  9. If-else • #!/bin/bash# Declare variable choice and assign value 4choice=4# Print to stdoutecho "1. Bash"echo "2. Scripting"echo "3. Tutorial"echo -n "Please choose a word [1,2 or 3]? "# Loop while the variable choice is equal 4# bash while loopwhile [ $choice -eq 4 ]; do# read user inputread choice# bash nested if/elseif [ $choice -eq 1 ] ; thenecho "You have chosen word: Bash" • else if [ $choice -eq 2 ] ; thenecho "You have chosen word: Scripting"elseif [ $choice -eq 3 ] ; thenecho "You have chosen word: Tutorial"elseecho "Please make a choice between 1-3 !"echo "1. Bash"echo "2. Scripting"echo "3. Tutorial"echo -n "Please choose a word [1,2 or 3]? "choice=4fi fifidone

  10. Aritmetik Karşılaştırma • -lt < • -gt > • -le <= • -ge >= • -eq == • -ne != • #!/bin/bash • # declare integers • NUM1=2 • NUM2=2 • if [ $NUM1 -eq $NUM2 ]; then • echo "Both Values are equal" • else • echo "Values are NOT equal" • fi

  11. String Karşılaştırma • = equal • != not equal • < less then • > greater then • -n s1 string s1 is not empty • -z s1 string s1 is empty • #!/bin/bash • #Declare string S1 • S1="Bash" • #Declare string S2 • S2="Scripting" • if [ $S1 = $S2 ]; then • echo "Both Strings are equal" • else • echo "Strings are NOT equal" • fi

  12. For loop • #!/bin/bash# bash for loopfor f in $( ls /var/ ); doecho $fdone

  13. While • #!/bin/bashCOUNT=6# bash while loopwhile [ $COUNT -gt 0 ]; doecho Value of count is: $COUNTlet COUNT=COUNT-1done

  14. Until • #!/bin/bashCOUNT=0# bash until loopuntil [ $COUNT -gt 5 ]; doecho Value of count is: $COUNTlet COUNT=COUNT+1done

  15. Fonksiyonlar • echoFunction() { echo "echo is Called" } fooBar() { echo "Functions are FUN!" } echoFunction; • fooBar; // fonksiyon çağırımı • echoFunction;

More Related