#!/bin/bash
clear
echo "Program Membuat Bangun Dua Dimensi"
echo
echo -n "Masukkan panjang[max 10]: "
read p
echo
echo -n "Ketikkan Line Bangun[1 angka/huruf/karakter]: "
read c
let b=0
let "h=$p+1"
if [ $h -lt 10 ]; then
while [ $b -ne 3 ]
do
echo
echo
echo "1 Gambar Kotak A"
echo "2 Gambar Kotak B"
echo "3 Exit"
echo -n "Masukkan Menu: "
read b
if [ $b -eq 1 ]; then
let j=0
while [ $j -ne 6 ]
do
echo "Jenis Kotak A: "
echo "1. Kotak satu"
echo "2. Kotak Diagonal Kanan Bawah"
echo "3. Kotak Diagonal Kanan Atas"
echo "4. Setengah Diagonal Atas"
echo "5. Setengah Diagonal Bawah"
echo "6. Menu Utama"
echo -n "Masukkan Jenis = "
read j
let "j=$j"
if [ $j -eq 1 ]; then
echo
echo "Kotak Satu"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $i -eq $x ] || [ $j -eq 0 ] || [ $j -eq $x ] || [ $a == $x ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 2 ]; then
echo
echo "Kotak Dua"
echo
let "i=0"
echo "Gambar yang dihasilkan : "
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $i -eq $x ] || [ $j -eq 0 ] || [ $j -eq $x ] || [ $a == $x ] || [ $a -ge $x ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 3 ]; then
echo
echo "Kotak Tiga"
echo
let "i=0"
echo "Gambar yang dihasilkan : "
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $i -eq $x ] || [ $j -eq 0 ] || [ $j -eq $x ] || [ $a == $x ] || [ $a -lt $x ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 4 ]; then
echo
echo "Kotak Empat"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $j -eq 0 ] || [ $a == $x ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 5 ]; then
echo
echo "Kotak Lima"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq $x ] || [ $j -eq $x ] || [ $a == $x ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
else
echo "Menu Tidak Tersedia"
fi
done
elif [ $b -eq 2 ]; then
let j=0
while [ $j -ne 6 ]
do
echo "Jenis Kotak B: "
echo "1. Kotak satu"
echo "2. Kotak Diagonal Kanan Bawah"
echo "3. Kotak Diagonal Kanan Atas"
echo "4. Setengah Diagonal Atas"
echo "5. Setengah Diagonal Bawah"
echo "6. Menu Utama"
echo -n "Masukkan Jenis = "
read j
let "j=$j"
if [ $j -eq 1 ]; then
echo
echo "Kotak Satu"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $i -eq $x ] || [ $j -eq 0 ] || [ $j -eq $x ] || [ $i == $j ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 2 ]; then
echo
echo "Kotak Dua"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $i -eq $x ] || [ $j -eq 0 ] || [ $j -eq $x ] || [ $i == $j ] || [ $i -lt $j ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 3 ]; then
echo
echo "Kotak Tiga"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $i -eq $x ] || [ $j -eq 0 ] || [ $j -eq $x ] || [ $i == $j ] || [ $i -ge $j ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 4 ]; then
echo
echo "Kotak Empat"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq 0 ] || [ $j -eq $x ] || [ $i == $j ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
elif [ $j -eq 5 ]; then
echo
echo "Kotak Lima"
echo
echo "Gambar yang dihasilkan : "
let "i=0"
let "x=$p-1"
while [ $i -lt $p ]
do
let "j=0"
while [ $j -lt $p ]
do
let "a=$i+$j"
if [ $i -eq $x ] || [ $j -eq 0 ] || [ $i == $j ]; then
echo -n "$c"
else
echo -n " "
fi
let "j=$j+1"
done
let "i=$i+1"
echo " "
done
fi
done
fi
done
else
echo "Panjang Maksimum adalah 10, Silahkan Ulangi"
fi
While Bertingkat Bash Shell
00.27 |
Label:
Pemrograman Shell