bash switch-case statement gives syntax error -


#!/bin/bash

echo "title: " read title echo "" until [ -n "$title" ] echo "please enter title: " read title echo "" done echo "author: " read author echo "" until [ -n "$author" ] 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" ] echo "error! book not exist!" #need code 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 : 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) main menu" echo "" echo -n "please enter choice: " read option

case $option in ) echo -n "new title: " read newtitle if [ "$oldtitle" = "$newtitle" ] echo "title same original" else all_title=`cut -f 1 -d ":" ./bookdb.txt` check=`echo "$all_title" | grep -i "\b""$newtitle""\b"` fi if [ -n "$check" ] echo "book title exists." else sed -i "s/$oldtitle:/$newtitle:/g" ./bookdb.txt echo "book title updated." fi b ) esac done

i can't run code on bash. there syntax error @ case selection @ line b )

which see no problem @ all

when using case statements, need end each clause ;;:

case $option in      )         #         ;;     b )         #         ;; esac 

you can read here more details on case statement.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -