Skip to content
Advertisement

making a Hotel management system in BashScript

I am unable to correct the error. I have tried searching on Google but i can’t figure out what my output is referring to. Its giving a line number but the code is right there. “fi” is used at the end of IF statements in scriptfiles. This is my code

#!/bin/bash

#Declaring all fucntions

#Menu Display Function
set_menu_choice(){
clear
echo "---------------------------------------------"
echo "HOTEL RESERVATION"
echo "-------------------------------------------"
echo "1: BOOK A ROOM."
echo "2: TO VIEW YOUR DATA."
echo 'Please enter the choice: '
read menu_choice
}

#FOR HOTEL SELECTION
roombooking(){

#rtype=ROOM TYPE, hnum=HOTEL NUMBER, pr=PRICE RANGE, sty=DAYS OF STAY. 
$i, $j, $x, $rtype, $price, $sty, $bill; 
$r;
#
clear
echo "ENTER YOUR PRIZE RANGE MINIMUM(4000): "
read price
#
#Price Check
echo "HOTELS AVAILABLE"
if [[ $price -lt 4000 ]]; then
echo "SORRY NO HOTEL AVAILABLE IN THIS RANGE"
echo "ENTER YOUR PRIZE RANGE AGAIN MINIMUM(4000): "
read price
else if [[ ( $price -gt 4000 && $price -lt 5000 ) ]]; then  
echo "HOTEL RAMADA" 
#
elif [[ ( $price -gt 5000 && $price -lt 7000 ) ]]; then 
echo "1=>HOTEL RAMADA."
echo "2=>TAJ MAHAL."
#
elif [[ ( $price -gt 7000 && $price -lt 9000 ) ]]; then 
echo "1=>HOTEL RAMADA."
echo "2=>TAJ MAHAL."
echo "3=>HOTEL MEHRAN." 
#
elif [[ ( $price -gt 9000 && $price -lt 10000 ) ]]; then    
echo "1=>HOTEL RAMADA."
echo "2=>TAJ MAHAL."
echo "3=>HOTEL MEHRAN." 
echo "4=>MOVE AND PICK."    
#   
elif [[ $price -gt 10000 ]]
echo "1=>PEARL CONTINENTAL."
echo "2=>MOVE AND PICK."
echo "3=>HOTEL MEHRAN."
echo "4=>TAJ MAHAL."
echo "5=>HOTEL RAMADA."
fi
}

# Main Work
printf 'nnn'
printf 'Hotel Management System'

# Calling Options Display Function
set_menu_choice

if [[ $menu_choice == 1 ]]; then
roombooking
else
echo "Display Data"
fi

echo "finshed"

I am attaching the output too Error while running the bashscript file

EDIT: After adding ; then in the last elif statement, I am getting the following error:

**Syntax Error Expected near Unexpected Token '}'**

Advertisement

Answer

First, you’re missing a ; then here:

elif [[ $price -gt 10000 ]]
echo "1=>PEARL CONTINENTAL."
echo "2=>MOVE AND PICK."
echo "3=>HOTEL MEHRAN."
echo "4=>TAJ MAHAL."
echo "5=>HOTEL RAMADA."
fi
}

Second, you’re getting a syntax error near unexpected token '}' because you did not close every statement. Just add a last fi after the current final one (inside the roombooking function also):

elif [[ $price -gt 10000 ]]; then
echo "1=>PEARL CONTINENTAL."
echo "2=>MOVE AND PICK."
echo "3=>HOTEL MEHRAN."
echo "4=>TAJ MAHAL."
echo "5=>HOTEL RAMADA."
fi
fi
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement