0

#!/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

2
  • try to slim down the problem... create a minimal example... Commented Jan 21, 2016 at 7:36
  • 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. Commented Jan 21, 2016 at 8:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

its correct! thank you so much on that link for the guide

Your Answer

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.