我尝试做一个简单的选择来选择一些东西。 但我有错误,有人可以帮助我吗?
$ vi sel2.sh
lagi='y'
while [ $lagi == 'y' ] || [ $lagi == 'Y' ];
do
clear
select menu in "Bakso" "Gado-Gado" "Exit";
case $REPLY in
1) echo -n "Banyak mangkuk =";
read jum
let bayar=jum*1500;
;;
2) echo -n "Banyak porsi =";
read jum
let bayar=jum*2000;
;;
3) exit 0
;;
*) echo "Sorry, tidak tersedia"
;;
esac
do
echo "Harga bayar = Rp. $bayar"
echo "THX"
echo
echo -n "Hitung lagi (y/t) :";
read lagi;
#untuk validasi input
while [ $lagi != 'y' ] && [ $lagi != 'Y' ] && [ $lagi != 't' ] && [ $lagi != 'T' ];
do
echo "Ops, isi lagi dengan (y/Y/t/Y)";
echo -n "Hitung lagi (y/t) :";
read lagi;
done
done
答案 0 :(得分:0)
尝试更改
select menu in "Bakso" "Gado-Gado" "Exit";
到
options=( "Bakso" "Gado-Gado" "Exit")
select menu in "${options[@]}"
答案 1 :(得分:0)
您的代码中存在许多结构性问题。
可能这就是你要找的东西:
#!/bin/bash
lagi='y'
while [ $lagi == 'y' ] || [ $lagi == 'Y' ]
do
clear
select menu in "Bakso" "Gado-Gado" "Exit"
do
case $REPLY in
1) echo -n "Banyak mangkuk =";
read jum
let bayar=jum*1500;
;;
2) echo -n "Banyak porsi =";
read jum
let bayar=jum*2000;
;;
3) exit 0
;;
*) echo "Sorry, tidak tersedia"
;;
esac
echo "Harga bayar = Rp. $bayar"
echo "THX"
echo
echo -n "Hitung lagi (y/t) :";
read lagi;
#untuk validasi input
while [ $lagi != 'y' ] && [ $lagi != 'Y' ] && [ $lagi != 't' ] && [ $lagi != 'T' ];
do
echo "Ops, isi lagi dengan (y/Y/t/Y)";
echo -n "Hitung lagi (y/t) :";
read lagi;
done
done
done