0

This code is not running it shows error:- whl_case_lop1: 25: whl_case_lop1: Syntax error: "elif" unexpected (expecting ";;")

#if [ -z 1ドル ]
#then
#rental=****unknown item****
#elif [ -n 1ドル ]
#then 
#rental=1ドル
#else [ -n 2ドル ]
#then
#rent=2ドル
#fi
echo "1. Vehicle_on_rent"
echo "2. Living_house"
echo -n "choose option [1 or 2]? "
read cate; 
if [ $cate -eq 1 ]; 
then
echo "Enter your vehicle type"
read rental 
case $rental in 
"car") echo "for $rental in 20/km";;
"van") echo "for $rental in 15/km";;
"jeep") echo "for $rental in 10/km";;
"bike") echo "for $rental in 5/km";;
*) echo "We can't find $rental for your vehicle"
elif [ $cate -eq 2 ]; 
then 
echo "Enter your Room requirement"
read rent
case $rent in
"1BHK") echo "for $rent is 10k";;
"2BHK") echo "for $rent is 15k";;
"3BHK") echo "for $rent is 20k";;
*) echo "we can't find $rent for your Requirement"
else
echo "Please check your requirements! Maybe you choose a wrong option"
fi
anubhava
791k67 gold badges604 silver badges671 bronze badges
asked Jul 13, 2015 at 12:08
1
  • 2
    paste your code on shellcheck.net Commented Jul 13, 2015 at 12:20

1 Answer 1

1

You need a ;; in your case's *) branch, and the case statement ends with the esac keyword: https://www.gnu.org/software/bash/manual/bashref.html#Conditional-Constructs

You might want to use the select statement, to restrict the user's responses:

PS3="Enter your vehicle type: "
select rental in car van jeep bike; do
 case $rental in 
 car) echo "for $rental in 20/km"; break ;;
 van) echo "for $rental in 15/km"; break ;;
 jeep) echo "for $rental in 10/km"; break ;;
 bike) echo "for $rental in 5/km"; break ;;
 *) echo "We can't find $rental for your vehicle" ;;
 esac
done

Indent your code to aid maintainability.

answered Jul 13, 2015 at 13:28
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.