0
votes

#!/bin/bash

echo "Title: " read title echo "" until [ -n "$title" ] do echo "Please enter title: " read title echo "" done echo "Author: " read author echo "" until [ -n "$author" ] do echo "Please enter author: " read author echo "" done

check=cat ./BookDB.txt | egrep -ie "\b""$title""\b" | egrep -ie "\b""$author""\b" if [ -z "$check" ] then echo "Error! Book does not exist!" #need some code to continue else echo "Book found!" all=cat ./BookDB.txt | grep -i "$title"

oldtitle=`echo "$all" | cut -d ":" -f1`
oldauthor=`echo "$all" | cut -d ":" -f2`
oldprice=`echo "$all" | cut -d ":" -f3`
oldavail=`echo "$all" | cut -d ":" -f4`
oldsold=`echo "$all" | cut -d ":" -f5`

fi while : do echo "" echo " a) Update title" echo " b) Update author" echo " c) Update price" echo " d) Update quantity available" echo " e) Update quantity sold" echo " f) Back to main menu" echo "" echo -n "Please enter your choice: " read option

case $option in a ) echo -n "New title: " read newtitle if [ "$oldtitle" = "$newtitle" ] then echo "Title is the same as original" else all_title=`cut -f 1 -d ":" ./BookDB.txt` check=`echo "$all_title" | grep -i "\b""$newtitle""\b"` fi if [ -n "$check" ] then echo "Book title already exists." else sed -i "s/$oldtitle:/$newtitle:/g" ./BookDB.txt echo "Book title successfully updated." fi b ) esac done

i can't run this code on bash. they say there is a syntax error at my CASE selection at this line b )

which i see no problem at all

1
try to slim down the problem... create a minimal example... - Chris Maes
all=cat ./BookDB.txt | grep -i "$title" is very suspect. Nothing to do with the case missing ;;, but I think you mean: all=$(grep -i "$title" ./BookDB.txt). There is another larger example above that line. - cdarke

1 Answers

1
votes

when using case statements, you need to end each clause with ;;:

case $option in 
    a )
        # do something
        ;;
    b )
        # do something
        ;;
esac

you can read here for more details on the case statement.