create account

How to Write a Shell Script with Bash? Turkish Tutorial #1 by sedatyildiz

View this thread on: hive.blogpeakd.comecency.com
· @sedatyildiz · (edited)
$35.44
How to Write a Shell Script with Bash? Turkish Tutorial #1
#### What Will I Learn?
In the first lesson we will learn how to create bash files and enter shell systems with a few examples.
- Shell Script
- Bash 4.4 


#### Requirements
Linux Operating System

#### Difficulty
Intermediate

#### Tutorial Contents
I'll show you how to write Shell Script with Bash on Linux operating systems. In this first lesson we will learn the "echo" and "read" constructs.

#### Curriculum
[How to Write a Shell Script with Bash? Turkish Tutorial #1](https://utopian.io/utopian-io/@sedatyildiz/how-to-write-a-shell-script-with-bash-turkish-tutorial-1)
 [How to Write a Shell Script with Bash? Turkish Tutorial #2](https://utopian.io/utopian-io/@sedatyildiz/how-to-write-a-shell-script-with-bash-turkish-tutorial-2)

<hr>
<br>


Linux işletim sistemlerinde kullandığımız standart komutlar ile yapabileceğimiz en yaygın ve kolay programlama dili olan Shell için mini programlar yazacağız. Kullanacağımız Bash teknolojisi yani Bourne Again Shell, kullanım kolaylığı açısından bize oldukça yardımcı olacak ve ileriki derslerimizde komut tamamlama gibi nimetlerini çokça kullanacağız.
Bildiğiniz üzere linux ve tüm unix distrolarda vazgeçilmez yönetim bölümümüz terminaldir, GUI ile ara yüz üzerinden yapılabilecek hemen her işlemi komut istemi yardımıyla gerçekleştirebilmekteyiz.  Bu dersimizde en baştan başlayarak bir .sh dosyası oluşturup programımıza bir kaç işlem yaptıracağız.

Ben Windows bir işletim sistemi kullandığım için linux bir sunucuya SSH bağlantısı gerçekleştirerek örneklendireceğim, siz terminal üzerinden çalışabilirsiniz.

![bash-1.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060241/nodmwho5sc6eyvpjgzwj.gif)

Öncelikle terminalimizi açıp <code>echo '#!/bin/sh' > utopian.sh</code> komutumuzu girerek **utopian.sh** isminde bir komut dosyası oluşturuyoruz. Burada **utopian.sh** örnek bir isimdir, siz başka birşey kullanabilirsiniz. Gördüğünüz **#!/bin/sh** bölümü, betikleri çalıştırabilmemiz için bütün yazdığımız programlarda gereklidir.
Ardından <code>echo 'echo Merhaba Utopian' >> utopian.sh</code> komutumuz ile oluşturduğumuz **utopian.sh** dosyasına **echo Merhaba Utopian** komutunu yazdırmış olduk. Bu da demek oluyor ki programımız bize **echo** ile Merhaba Utopian yazısını basacak.
<code>chmod 755 utopian.sh</code> komutu ile **utopian.sh** dosyamıza **755** izni yani **okuma ve çalıştırma** yetkisini veriyoruz.
Akabinde <code>sh utopian.sh</code> komutunu yazarak oluşturduğumuz shell scripti çalıştırabiliriz ve bize **Merhaba Utopian** şeklinde bir yanıt verdiğini görebiliriz.


Bunun gibi **echo** ile bir çok karşılama cümlesi bastırabiliriz.
![bash-2.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060678/ffgpazslcrftiz49404d.gif)
<code>echo 'echo Utopian' >> utopian.sh</code>
<code>echo 'echo SedatYildiz' >> utopian.sh</code>
<code>echo 'echo Steemit' >> utopian.sh</code>
<code>echo 'echo Deneme123' >> utopian.sh</code>
Yukarıdaki örneklerde **Merhaba Utopian** yerine yine aynı yöntem ile farklı kelimeler bastırdık, farklı cümleler ve kelimeleri bu yöntem ile istediğiniz kadar programımıza yazdırabiliyoruz.

İlk adımımızdan yani dosyamızı oluşturup içerisine çalıştırma komutunu verdikten sonra **echo** ile komut istemcisinde çalışmak yerine kolaylık olması açısından direkt terminal üzerinden **nano** editörümüz ile bash dosyamızı açabilir ve komutlarımızı bu şekilde girebiliriz.
![bash-3.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060969/wnqo8xsjkxlluivkkddu.gif)
Gireceğimiz <code>nano utopian.sh</code> komutu ile oluşturduğumuz **utopian.sh** içerisine giriş yapabiliyoruz. Bir üstteki dört satırlık çıktı örneğimizi son haliyle görebiliriz.

Daha komplike bir örnek yapalım ve bu sefer programımızdan bir soru karşılığı yanıt alalım. Bunun için nano editörü ile komutlarımızı yazacağız.
![bash-4.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516061138/nnjlq6p6htfzm659gcij.gif)
<code>echo İsmin nedir?</code> --> İsmin nedir? şeklinde bir çıktı bastırıyoruz.
<code>read isim</code> --> Programımıza "isim" adındaki değişkeni okumasını söylüyoruz.
<code>echo "Merhaba $isim . Memnun oldum."</code> --> Değişkeni belirleyip, okuduktan sonra basacağı çıktıyı söylüyoruz.

Hepsi tamamlandığında **CTRL+X ve Y** tuşları ile .sh yi kaydedip editörümüzden çıkıyoruz ve <code>sh utopian.sh</code> komutu ile programımızı çalıştırdığımızda bize ismimizi soruyor. Örneğin ben **sedatyildiz** yazdım ve yukarıdaki komutlar dolayısıyla **Merhaba sedatyildiz . Memnun oldum.** şeklinde bir yanıt verdi.

Son örneğimizde de  shell scriptimize ufak bir matematik işlemi yaptıralım.
![ezgif.com-video-to-gif.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516061931/wvd5ippfsq0uqcrrawf0.gif)
<code>echo -n "Sonuc = "</code> --> Alacağı değişkenin ekrana basmasını söyledik.
<code>echo $((324324 + 1234))</code> --> 324324 ve 1234 sayılarını toplayıp sonuca aktarttık.
Kaydedip sh utopian.sh ile programımızı çalıştırdığımızda bize başarıyla toplamı yani **Sonuc = 325558** çıktısını yazdırmış oldu.

Bu derste öğrendiğimiz yapılar ile sonraki dersimizde, yaptırdığımız matematik işlemini sh içerisine yazmayıp direkt komutlarla soracağız ve programımıza hesaplatacağız.

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@sedatyildiz/how-to-write-a-shell-script-with-bash-turkish-tutorial-1">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsedatyildiz
permlinkhow-to-write-a-shell-script-with-bash-turkish-tutorial-1
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":90001159,"name":"gnu_bash","full_name":"gitGNU/gnu_bash","html_url":"https://github.com/gitGNU/gnu_bash","fork":false,"owner":{"login":"gitGNU"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","tr","linux","shell","bash"],"users":["sedatyildiz"],"links":["https://utopian.io/utopian-io/@sedatyildiz/how-to-write-a-shell-script-with-bash-turkish-tutorial-1","https://utopian.io/utopian-io/@sedatyildiz/how-to-write-a-shell-script-with-bash-turkish-tutorial-2","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060241/nodmwho5sc6eyvpjgzwj.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060678/ffgpazslcrftiz49404d.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060969/wnqo8xsjkxlluivkkddu.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516061138/nnjlq6p6htfzm659gcij.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516061931/wvd5ippfsq0uqcrrawf0.gif"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060241/nodmwho5sc6eyvpjgzwj.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060678/ffgpazslcrftiz49404d.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516060969/wnqo8xsjkxlluivkkddu.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516061138/nnjlq6p6htfzm659gcij.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516061931/wvd5ippfsq0uqcrrawf0.gif"],"moderator":{"account":"scipio","time":"2018-01-16T13:21:21.937Z","reviewed":true,"pending":false,"flagged":false}}
created2018-01-16 00:30:24
last_update2018-01-17 18:32:27
depth0
children9
last_payout2018-01-23 00:30:24
cashout_time1969-12-31 23:59:59
total_payout_value25.222 HBD
curator_payout_value10.218 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,406
author_reputation4,535,285,897,770
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,822,414
net_rshares4,704,352,172,434
author_curate_reward""
vote details (46)
@irfandemire2084 ·
Yakışıklı post olmuş.
properties (22)
authorirfandemire2084
permlinkre-sedatyildiz-how-to-write-a-shell-script-with-bash-turkish-tutorial-1-20180116t123515936z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-16 12:35:15
last_update2018-01-16 12:35:15
depth1
children1
last_payout2018-01-23 12:35:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length21
author_reputation6,691,727,725,489
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,929,821
net_rshares0
@sedatyildiz ·
Teşekkür ederim.
properties (22)
authorsedatyildiz
permlinkre-irfandemire2084-re-sedatyildiz-how-to-write-a-shell-script-with-bash-turkish-tutorial-1-20180116t123854244z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-16 12:38:57
last_update2018-01-16 12:38:57
depth2
children0
last_payout2018-01-23 12:38:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length16
author_reputation4,535,285,897,770
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,930,452
net_rshares0
@matematikciemre ·
emeğinize sağlık
properties (22)
authormatematikciemre
permlinkre-sedatyildiz-how-to-write-a-shell-script-with-bash-turkish-tutorial-1-20180116t012630352z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-16 01:26:36
last_update2018-01-16 01:26:36
depth1
children1
last_payout2018-01-23 01:26:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length16
author_reputation3,736,149,759,917
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,830,501
net_rshares0
@sedatyildiz ·
Çok teşekkürler.
properties (22)
authorsedatyildiz
permlinkre-matematikciemre-re-sedatyildiz-how-to-write-a-shell-script-with-bash-turkish-tutorial-1-20180116t014015816z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-16 01:40:18
last_update2018-01-16 01:40:18
depth2
children0
last_payout2018-01-23 01:40:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length16
author_reputation4,535,285,897,770
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,832,458
net_rshares0
@scipio ·
Thank you for the contribution. It has been approved.

Suggestions for this and future bash (shell) tutorial series:
- `sh` is not `bash` and so if your script uses `bash` (2nd generation, "Bourne Again sh"), then you should be more specific and use `bash` in your shebang;
- in essence you only created a .sh file (you could have used `touch` instead of echo'ing, but alright), showed how to run a .sh file, chmod'ed it t 755 (not explaining what those numbers mean!), you appended some text, read user input, and did some extremely trivial math additions. Of course in "part 1" of a series you need to start somewhere, but I'd like to see **on this contribution** that you change the "What will I learn?" to "creating, modifying and running `sh files": telling users that they will learn shell scripting is a bit misleading...
- I'm looking forward to parts 2 and next of your shellscript tutorial series, but make sure to cover **focused** topics/concepts per tutorial and explain exactly what you are doing where, why and how.
@scipio

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authorscipio
permlinkre-sedatyildiz-how-to-write-a-shell-script-with-bash-turkish-tutorial-1-20180116t132945986z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-16 13:29:45
last_update2018-01-16 13:29:45
depth1
children1
last_payout2018-01-23 13:29:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,157
author_reputation34,229,826,851,736
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,940,371
net_rshares0
@sedatyildiz ·
Hello, your edit has been made. I tried to keep it simple because it was the first lesson because you know a little complicated language structure. The next derste mathematical operations will be a bit more complex. Thank you for your approval and your interest.
properties (22)
authorsedatyildiz
permlinkre-scipio-re-sedatyildiz-how-to-write-a-shell-script-with-bash-turkish-tutorial-1-20180116t144337082z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-16 14:43:39
last_update2018-01-16 14:43:39
depth2
children0
last_payout2018-01-23 14:43:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length262
author_reputation4,535,285,897,770
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,955,475
net_rshares0
@tarikhakan55 ·
Kodcumuz iş başında yine... Maşallah...
👍  
properties (23)
authortarikhakan55
permlinkre-sedatyildiz-2018116t13239434z
categoryutopian-io
json_metadata{"tags":["utopian-io","tr","linux","shell","bash"],"app":"esteem/1.5.0","format":"markdown+html","community":"esteem"}
created2018-01-16 00:32:42
last_update2018-01-16 00:32:42
depth1
children1
last_payout2018-01-23 00:32:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length39
author_reputation38,506,275,601,183
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries
0.
accountesteemapp
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,822,786
net_rshares2,307,999,097
author_curate_reward""
vote details (1)
@sedatyildiz ·
Teşekkür ediyorum abicim :)
properties (22)
authorsedatyildiz
permlinkre-tarikhakan55-re-sedatyildiz-2018116t13239434z-20180116t003420388z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-16 00:34:21
last_update2018-01-16 00:34:21
depth2
children0
last_payout2018-01-23 00:34:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length27
author_reputation4,535,285,897,770
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,823,044
net_rshares0
@utopian-io ·
### Hey @sedatyildiz I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-sedatyildiz-how-to-write-a-shell-script-with-bash-turkish-tutorial-1-20180117t124506243z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-17 12:45:06
last_update2018-01-17 12:45:06
depth1
children0
last_payout2018-01-24 12:45:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,509
author_reputation152,955,367,999,756
root_title"How to Write a Shell Script with Bash? Turkish Tutorial #1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,163,853
net_rshares0