-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15-if_ornekleri.sh
executable file
·134 lines (92 loc) · 1.92 KB
/
15-if_ornekleri.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /bin/bash
#Konu anlatımı: https://alisezisli.com.tr/shell-script-9-karar-yapilari-if-elif-else
#isim değişkeninin değerine göre bir komut çalıştıralım:
isim="Khabib"
if [[ "$isim" = "Khabib" ]]
then
echo "I'm gonna smash your boy."
fi
#if-else örneği:
isim="Not Khabib"
if [[ "$isim" = "Khabib" ]]
then
echo "I'm gonna smash your boy."
else
echo "What's your name again?!?"
fi
#if-elif-else örneği:
isim="Hamilton"
if [[ "$isim" = "Hamilton" ]]
then
echo "Leave it to me, Bono..."
elif [[ "$isim" = "Bottas" ]]
then
echo "To whom it may concern..."
elif [[ "$isim" = "Ricciardo" ]]
then
echo "Shooooeeeeyyy!!!"
else
echo "Mazepin sucks."
fi
#isim değeri, kullanıcıdan alınacak:
printf "Bugün kim olmak istersin?: "
read isim
if [[ "$isim" = "Hamilton" ]]
then
echo "Leave it to me, Bono..."
elif [[ "$isim" = "Bottas" ]]
then
echo "To whom it may concern..."
elif [[ "$isim" = "Ricciardo" ]]
then
echo "Shooooeeeeyyy!!!"
else
echo "Mazepin sucks."
fi
# komuta bağlı koşullar
# /etc/passwd dosyasında "root" kelimesini ara
if grep root /etc/passwd > /dev/null
then
echo "root bulundu"
else
echo "dosyada root yok"
fi
#sayısal değerlerin karşılaştırılması
sayi1=35
sayi2=28
if [[ $sayi1 -gt $sayi2 ]]
then
echo $sayi1 büyüktür $sayi2
elif [[ $sayi1 -lt $sayi2 ]]
then
echo $sayi1 küçüktür $sayi2
else
echo $sayi1 eşittir $sayi2
fi
#string değerlerin karşılaştırılması
str1="Ali"
str2="Gnu"
if [[ "$str1" < "$str2" ]]
then
echo $str1 önce geliyor
else
echo $str2 önce geliyor
fi
# AND OR NOT örnekleri
# AND örneği:
yas=30
if [[ (${yas} -gt 18) && (${yas} -lt 70) ]]
then
echo "Reşit olabilirsin ama emekli olamazsın."
fi
# OR örneği:
dosya="/bin/bash"
if [[ "${dosya}" = "/bin/bash" || "${dosya}" = "/bin/sh" ]]
then
echo "Hâlâ umut var."
fi
# NOT örneği:
if [[ !(-f "/etc/httpd.conf") ]]
then
echo "/etc/httpd.conf dosyası bulunamadı."
fi