#!/bin/bashecho "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`
網絡 同時: 做 回聲 「」 回聲 「一)更新標題」 回聲 「B)更新作者」 回聲 「C)更新價格」 回聲「d)更新量可用」 回聲「E)更新銷售數量」 回聲「F)返回到主菜單」 回聲「」回聲 -n「請輸入您的選擇:」 讀選項
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
我不能運行巴蜀此代碼。他們說有一個語法錯誤,在我的情況下選擇在該行 B)
我使用情況報表時,在所有
儘量減少問題...創建一個最小的例子... –
'all = cat ./BookDB.txt | grep -i「$ title」'是非常可疑的。 'case'缺少'';'',但我認爲你的意思是:'all = $(grep -i「$ title」./BookDB.txt)''。這條線上方還有另一個更大的例子。 – cdarke