Home » Struktur if sederhana di bash shell script

Struktur if sederhana di bash shell script

Berikut struktur if di bash shell script di linux.

1
2
3
4
5
if [ ekspresi ]; then
jika_ekspresinya_benar
else
jika_ekspresinya_salah
fi

Contohnya

1
2
3
4
5
6
7
8
#!/bin/sh
echo -n "Masukkan nama anda : "
read nama
if [ "$nama" = "adit" ]; then
echo "OK"
else
echo "Salah"
fi

hasilnya jika benar

1
2
3
[root@localhost ~]# ./if.sh
Masukkan nama anda : adit
OK

hasilnya jika salah

[root@localhost ~]# ./if.sh
Masukkan nama anda : adflk
Salah

Ok.. Berikut script sederhana banget dari newbie ^_^

Referensi :
http://www.tech-recipes.com/rx/316/bournebash-shell-script-while-loop-syntax/
http://www.justlinux.com/nhf/Programming/Introduction_to_bash_Shell_Scripting.html

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>