Slide 1

Slide 1 text

BASH 101 Geliştiriciler İçin

Slide 2

Slide 2 text

Uğur "vigo" Özyılmazel vigobronx vigo

Slide 3

Slide 3 text

bash Bourne Again SHell

Slide 4

Slide 4 text

Brian J. Fox

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

shell Komutları çalıştıran Makro işlemci 1

Slide 7

Slide 7 text

shell Komut yorumlayıcısı 2

Slide 8

Slide 8 text

shell Programlama Dili 3

Slide 9

Slide 9 text

Mac OS X (BSD) komutları ile Ubuntu / Linux komutları farklılık gösterir

Slide 10

Slide 10 text

$ help # help $ help pwd help

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

konfigürasyon ~/.profile ~/.bashrc Kullancı Bazında } /etc/profile /etc/bashrc Sistem Bazında }

Slide 13

Slide 13 text

konfigürasyon 1 ~/.profile 2 ~/.bashrc

Slide 14

Slide 14 text

#!/usr/bin/env bash source "$HOME/.bashrc" ~/.profile

Slide 15

Slide 15 text

# non interactive shell [ -z "$PS1" ] && return export DOTFILES_PATH="$HOME/Dotfiles" source $DOTFILES_PATH/shell/env source $DOTFILES_PATH/shell/alias source $DOTFILES_PATH/shell/ls_colors # Load private files # ------------------------------------------------------ # Loads every file under private/ folder! if [[ -d $DOTFILES_PATH/private ]]; then if [ "$(ls -A $DOTFILES_PATH/private)" ]; then ~/.bashrc

Slide 16

Slide 16 text

Environment Variables env

Slide 17

Slide 17 text

TERM_PROGRAM=Apple_Terminal COMP_WORDBREAKS= "'><;|&(: TERM=xterm-256color SHELL=/bin/bash HISTSIZE=30000 TMPDIR=/var/folders/gz/hvbfjmnx5z3bl6k05bp4w04h0000gn/T/ DOCKER_HOST=tcp://192.168.59.103:2376 Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.PyiyHWlqqs/ Render TERM_PROGRAM_VERSION=343.7 TERM_SESSION_ID=59036979-ACF9-409F-9141-9AAA2941844E CDPATH=.:..:../..:/Users/vigo/Desktop/Dropbox SVN_EDITOR=mate -w HISTFILESIZE=30000 USER=vigo DOCKER_TLS_VERIFY=1 PATH=/Users/vigo/.rbenv/shims:/Users/vigo/.rbenv/bin:/usr/local/heroku bin:/usr/local/heroku/bin:/Users/vigo/bin:/usr/local/sbin:/usr/local/ bin:/usr/bin:/bin:/usr/sbin:/sbin PWD=/Users/vigo/Development/Source/sinatra EDITOR=mate -w

Slide 18

Slide 18 text

Prompt Shell $PS1

Slide 19

Slide 19 text

PS1='\h:\W \u\$ ' \h Ugurs-MacBook-Air \W ~ \u vigo

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

https://github.com/vigo/dotfiles-universal http://linuxconfig.org/bash-prompt-basics

Slide 22

Slide 22 text

gündelik komutlar curl touch mkdir alias man sudo history grep xargs less pwd ls cd cp mv rm chown ln find awk cat git ps more chmod

Slide 23

Slide 23 text

komut ? $ man $ man ls $ man pwd $ man -k "kelime"

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

h

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

man help (less) / n sonraki bulunan kelime N önceki bulunan kelime f 1 ekran ileri git b 1 ekran geri git g ilk satıra git G son satıra git q çık

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

alt man sayfaları $ man $ man 3 getcwd $ man 2 chdir

Slide 30

Slide 30 text

alias $ alias # hepsini göster $ alias XX='' $ alias la='ls -al' $ alias la # göster

Slide 31

Slide 31 text

alias $ alias ls='ls -al' $ \ls # orijinal ls ile Ezdiğiniz orijinal komutları \ ön eki ile çağırabilirsiniz!

Slide 32

Slide 32 text

Unix Felsefesi Birbiriyle konuşan küçük küçük programcılar!

Slide 33

Slide 33 text

pipe $ | | | ...

Slide 34

Slide 34 text

pipe $ man 5 -t nanorc | open -f -a preview nano'nun konfigürasyon dosyası ile ilgili 5.dökümanı pdf haline getirmek. Mac OS X için geçerlidir.

Slide 35

Slide 35 text

$ find . -iname '*1*.jpg' pipe ./file_1.jpg ./file_10.jpg ./file_11.jpg ./file_12.jpg ./file_13.jpg ./file_14.jpg ./file_15.jpg ./file_16.jpg ./file_17.jpg ./file_18.jpg ./file_19.jpg

Slide 36

Slide 36 text

$ find . -iname '*1*.jpg' | xargs -n 1 echo "Bulunan:" pipe Bulunan: ./file_1.jpg Bulunan: ./file_10.jpg Bulunan: ./file_11.jpg Bulunan: ./file_12.jpg Bulunan: ./file_13.jpg Bulunan: ./file_14.jpg Bulunan: ./file_15.jpg Bulunan: ./file_16.jpg Bulunan: ./file_17.jpg Bulunan: ./file_18.jpg Bulunan: ./file_19.jpg

Slide 37

Slide 37 text

$ find . -iname '*1*.jpg' | xargs -n 1 rm pipe

Slide 38

Slide 38 text

redirection $ ls tmp/ file_1.jpg file_12.jpg file_15.jpg file_18.jpg file_20.jpg file_5.jpg file_8.jpg file_10.jpg file_13.jpg file_16.jpg file_19.jpg file_3.jpg file_6.jpg file_9.jpg file_11.jpg file_14.jpg file_17.jpg file_2.jpg file_4.jpg file_7.jpg $ ls tmp/ > dir_list.txt

Slide 39

Slide 39 text

redirection $ > dosya
 # yoksa oluştur ya da üzerine yaz $ >> dosya
 # ek yap (append) $ < dosya
 $ sort -r < dir_list.txt 
 # dosyayı komuta yönlendir

Slide 40

Slide 40 text

komut kombinasyonu $ ; ; 
 # herhangibiri hata verse bile diğeri devam eder. $ && && 
 # herhangibiri hata verirse diğer işlemler çalışmaz. $ || || 
 # komutlar bitince sekans durur.

Slide 41

Slide 41 text

BASH Programlama Dilidir!

Slide 42

Slide 42 text

standart • Değişken tanımlamaları • Fonksiyon tanımlamaları • Kontrol mekanizmaları • Döngü mekanizmaları • Hata yakalama mekanizmaları • Regular Expression

Slide 43

Slide 43 text

değişken A=5 # = ile değişken arası A="5" # bitişik olmalı! A=$(date) # date komutunun değeri A=`date` # date komutunun değeri export A="Hello" Default: Global Scope

Slide 44

Slide 44 text

fonksiyon function (){ # buraya kod } function md() { mkdir -p "$@" && cd "$@" }

Slide 45

Slide 45 text

fonksiyon deneme(){ echo "$@" } deneme2(){ echo "$1" } deneme 1 2 3 4 # => 1 2 3 4 deneme2 1 2 3 4 # => 1

Slide 46

Slide 46 text

fonksiyon A=5 B="lego" deneme(){ local A="vigo" echo "\$A: ${A} \$B: ${B}" } deneme # => $A: vigo $B: lego

Slide 47

Slide 47 text

kontrol if [[ durum ]]; then # kod fi if [[ durum ]]; then # kod elif [[ durum ]]; then # kod fi

Slide 48

Slide 48 text

kontrol # Ubuntu ? if [[ `which lsb_release` ]]; then if [[ `lsb_release -i | awk '{print $3}'` == "Ubuntu" ]]; then source $DOTFILES_PATH/shell/ubuntu_specific fi fi # Mac ? if [[ `uname` == "Darwin" ]]; then source $DOTFILES_PATH/shell/mac_specific fi

Slide 49

Slide 49 text

döngü export DOTFILES_PATH="$HOME/Dotfiles" for file in $DOTFILES_PATH/private/*; do source $file done x=0 read_file="/Users/vigo/Desktop/bash101-demo/dummy_text" cat $read_file | while read line; do x=$(($x+1)) echo "Satır: ${x}, ${line}" done

Slide 50

Slide 50 text

döngü typeset -a test_array test_array=( "username" "vigo" "password" "secret" ) test_array_count=${#test_array[*]} for ((i=0; i<=$((($test_array_count/2)-1)); i++)); do key="${test_array[(0+($i*2))]}" value="${test_array[(1+($i*2))]}" echo "${i} : ${key} ${value}" done

Slide 51

Slide 51 text

Teşekkürler, Sorular ?