Contoh BashScript Aritmatika :
- Penjumlahan
#!/bin/bash
echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b
let “ hasil = $a+$b “
echo “ hasil = $hasil “
Setelah file dieksekusi maka hasilnya
Masukkan angka = 2
Masukkan angka = 3
hasil = 5
- Pengurangan
#!/bin/bash
echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b
let “ hasil = $a-$b “
echo “ hasil = $hasil “
Setelah file dieksekusi maka hasilnya
Masukkan angka = 5
Masukkan angka = 3
hasil = 2
- Perkalian
#!/bin/bash
echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b
let “ hasil = $a*b “
echo “ hasil = $hasil “
Setelah file dieksekusi maka hasilnya
Masukkan angka = 3
Masukkan angka = 5
hasil = 15
- Pembagian
#!/bin/bash
echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b
let “ hasil = $a/$b “
echo “ hasil = $hasil “
Setelah file dieksekusi maka hasilnya
Masukkan angka = 20
Masukkan angka = 5
hasil = 4
0 comments:
Post a Comment